Skip to content

Commit 39f029e

Browse files
committed
feat: compile generated chain srcs with esbuild
1 parent a79cde6 commit 39f029e

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

packages/graz/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"@walletconnect/utils": "^2.8.1",
4444
"@web3modal/standalone": "^2.4.3",
4545
"commander": "^11.0.0",
46+
"esbuild": "^0.18.4",
4647
"zustand": "^4.3.8"
4748
},
4849
"devDependencies": {

packages/graz/src/cli/build-js.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as esbuild from "esbuild";
2+
import { globby } from "globby";
3+
4+
export const buildJs = async (format: esbuild.Format) => {
5+
const paths = await globby(["chains/**/*.ts"]);
6+
await esbuild.build({
7+
allowOverwrite: true,
8+
bundle: false,
9+
entryPoints: [...paths],
10+
format,
11+
outdir: "chains",
12+
});
13+
};

packages/graz/src/cli/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import os from "node:os";
33

44
import * as p from "@clack/prompts";
55
import { Command } from "commander";
6+
import type { Format } from "esbuild";
67
import pMap from "p-map";
78

9+
import { buildJs } from "./build-js";
810
import { cloneRegistry } from "./clone-registry";
911
import { getChainPaths } from "./get-chain-paths";
1012
import { makeRootSources } from "./make-root-sources";
@@ -33,37 +35,40 @@ const cli = async () => {
3335
"-T, --testnet <chainPaths...>",
3436
'generate given testnet chain paths separated by spaces (e.g. "atlantic bitcannadev cheqdtestnet")',
3537
)
38+
.option("--format <format>", "specify javascript module format: cjs, esm (defaults to cjs)")
3639
.action(async (options) => {
3740
const customRegistry = options.registry as string | undefined;
3841
const mainnetFilter = options.mainnet as string[] | undefined;
3942
const testnetFilter = options.testnet as string[] | undefined;
4043

44+
const jsFormat: Format = options.format === "esm" || options.format === "cjs" ? options.format : "cjs";
45+
4146
p.intro("graz generate");
4247
const s = p.spinner();
4348

44-
// p.log.step("Cloning chain registry...");
4549
s.start(`Cloning chain registry`);
4650
await cloneRegistry(customRegistry);
4751
s.stop("Cloned chain registry ✅");
4852

49-
// p.log.step("Retrieving chain paths...");
5053
s.start("Retrieving chain paths");
5154
const { mainnetPaths, testnetPaths } = await getChainPaths({ mainnetFilter, testnetFilter });
5255
s.stop("Retrieved chain paths ✅");
5356

54-
// p.log.step("Generating chain sources...");
5557
s.start("Generating chain sources");
5658
await fs.rm("chains/", { recursive: true, force: true });
5759
await pMap([...mainnetPaths, ...testnetPaths], makeSources, {
5860
concurrency: Math.max(1, (os.cpus() || { length: 1 }).length - 1),
5961
});
6062
s.stop("Generated chain sources ✅");
6163

62-
// p.log.step("Generating chain index...");
6364
s.start("Generating chain index");
6465
await makeRootSources({ mainnetPaths, testnetPaths });
6566
s.stop("Generated chain index ✅");
6667

68+
s.start("Compiling typescript sources to javascript");
69+
await buildJs(jsFormat);
70+
s.stop("Compiled sources ✅");
71+
6772
p.outro('Generate complete! You can import `mainnetChains` and `testnetChains` from "graz/chains". 🎉');
6873
});
6974

packages/graz/stubs/chains-index.ts.stub

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import { createRequire } from "node:module";
2-
31
import type { ChainData, ChainName, ReturnTuple } from "./generated";
42

5-
const require = createRequire(import.meta.url);
6-
73
export * from "./generated";
84

95
export const getChainData = <T extends ChainName>(pathOrPaths: T | T[]) => {

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)