Skip to content

Commit

Permalink
chore(website): remove bundling for @crypto-frontmatter
Browse files Browse the repository at this point in the history
  • Loading branch information
fuxingloh committed Nov 15, 2023
1 parent e4d1ea9 commit 51d19b0
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/crypto-frontmatter/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class MirrorCommand extends Command {
async execute(): Promise<number | void> {
await mkdir(this.target, { recursive: true });

const collections = await getInstalledFrontmatterCollection();
const collections = getInstalledFrontmatterCollection();
for (const collection of collections) {
let count = 0;
const indexArray = await getFrontmatterIndexArray(collection.caip2, collection.namespace);
Expand Down
18 changes: 12 additions & 6 deletions packages/crypto-frontmatter/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createHash } from 'node:crypto';
import { readdir, readFile, stat } from 'node:fs/promises';
import { existsSync, readdirSync, readFileSync } from 'node:fs';
import { readFile, stat } from 'node:fs/promises';
import { join } from 'node:path';

export interface FrontmatterLink {
Expand Down Expand Up @@ -40,6 +41,7 @@ export interface FrontmatterContent extends FrontmatterIndex {
}

export interface FrontmatterCollection {
name: string;
caip2: string;
namespace: string;
}
Expand Down Expand Up @@ -92,19 +94,23 @@ export function getNodeModulesPath(caip2: string, namespace: string, file: strin
);
}

export async function getInstalledFrontmatterCollection(): Promise<FrontmatterCollection[]> {
export function getInstalledFrontmatterCollection(): FrontmatterCollection[] {
const scopePath = join('node_modules', '@crypto-frontmatter');
const collections: FrontmatterCollection[] = [];

for (const dir of await readdir(scopePath)) {
for (const dir of readdirSync(scopePath)) {
const packagePath = join(scopePath, dir, 'package.json');
if (!(await hasFile(packagePath))) {
if (!existsSync(packagePath)) {
continue;
}
const contents = await readFile(packagePath, {
const contents = readFileSync(packagePath, {
encoding: 'utf-8',
});
collections.push(JSON.parse(contents).config);
const packageJson = JSON.parse(contents);
collections.push({
name: packageJson.name,
...packageJson.config,
});
}
return collections;
}
Expand Down
70 changes: 57 additions & 13 deletions packages/crypto-frontmatter/src/index.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,63 @@ it('should getFrontmatterContent of eip155:1/erc20:0', async () => {
expect(frontmatterContent).toBeUndefined();
});

it('should getInstalledFrontmatterCollection', async () => {
const collections = await getInstalledFrontmatterCollection();
it('should getInstalledFrontmatterCollection()', async () => {
const collections = getInstalledFrontmatterCollection();
expect(collections).toStrictEqual([
{ caip2: 'eip155:1', namespace: 'erc20' },
{ caip2: 'eip155:10', namespace: 'erc20' },
{ caip2: 'eip155:1313161554', namespace: 'erc20' },
{ caip2: 'eip155:137', namespace: 'erc20' },
{ caip2: 'eip155:42161', namespace: 'erc20' },
{ caip2: 'eip155:42220', namespace: 'erc20' },
{ caip2: 'eip155:43114', namespace: 'erc20' },
{ caip2: 'eip155:56', namespace: 'erc20' },
{ caip2: 'eip155:8453', namespace: 'erc20' },
{ caip2: 'tip474:728126428', namespace: 'trc10' },
{ caip2: 'tip474:728126428', namespace: 'trc20' },
{
caip2: 'eip155:1',
name: '@crypto-frontmatter/eip155-1-erc20',
namespace: 'erc20',
},
{
caip2: 'eip155:10',
name: '@crypto-frontmatter/eip155-10-erc20',
namespace: 'erc20',
},
{
caip2: 'eip155:1313161554',
name: '@crypto-frontmatter/eip155-1313161554-erc20',
namespace: 'erc20',
},
{
caip2: 'eip155:137',
name: '@crypto-frontmatter/eip155-137-erc20',
namespace: 'erc20',
},
{
caip2: 'eip155:42161',
name: '@crypto-frontmatter/eip155-42161-erc20',
namespace: 'erc20',
},
{
caip2: 'eip155:42220',
name: '@crypto-frontmatter/eip155-42220-erc20',
namespace: 'erc20',
},
{
caip2: 'eip155:43114',
name: '@crypto-frontmatter/eip155-43114-erc20',
namespace: 'erc20',
},
{
caip2: 'eip155:56',
name: '@crypto-frontmatter/eip155-56-erc20',
namespace: 'erc20',
},
{
caip2: 'eip155:8453',
name: '@crypto-frontmatter/eip155-8453-erc20',
namespace: 'erc20',
},
{
caip2: 'tip474:728126428',
name: '@crypto-frontmatter/tip474-728126428-trc10',
namespace: 'trc10',
},
{
caip2: 'tip474:728126428',
name: '@crypto-frontmatter/tip474-728126428-trc20',
namespace: 'trc20',
},
]);
});
1 change: 1 addition & 0 deletions packages/crypto-frontmatter/src/require.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* if you want to use it.
* For example, you must install @crypto-frontmatter/eip155-1-erc20 if you want to use eip155:1/erc frontmatter.
*
* @deprecated scheduled for removal
* @param caip2 {string}
* @param type {string}
* @param path {string}
Expand Down
5 changes: 5 additions & 0 deletions website/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { getInstalledFrontmatterCollection } from 'crypto-frontmatter';

/** @type {import('next').NextConfig} */
const nextConfig = {
env: {
BASE_URL: process.env.NEXT_PUBLIC_URL ?? `https://${process.env.VERCEL_URL}` ?? 'https://frontmatter.levain.tech',
},
experimental: {
serverComponentsExternalPackages: getInstalledFrontmatterCollection().map((collection) => collection.name),
},
trailingSlash: false,
reactStrictMode: true,
swcMinify: true,
Expand Down

0 comments on commit 51d19b0

Please sign in to comment.