@@ -3,8 +3,10 @@ import os from "node:os";
3
3
4
4
import * as p from "@clack/prompts" ;
5
5
import { Command } from "commander" ;
6
+ import type { Format } from "esbuild" ;
6
7
import pMap from "p-map" ;
7
8
9
+ import { buildJs } from "./build-js" ;
8
10
import { cloneRegistry } from "./clone-registry" ;
9
11
import { getChainPaths } from "./get-chain-paths" ;
10
12
import { makeRootSources } from "./make-root-sources" ;
@@ -33,37 +35,40 @@ const cli = async () => {
33
35
"-T, --testnet <chainPaths...>" ,
34
36
'generate given testnet chain paths separated by spaces (e.g. "atlantic bitcannadev cheqdtestnet")' ,
35
37
)
38
+ . option ( "--format <format>" , "specify javascript module format: cjs, esm (defaults to cjs)" )
36
39
. action ( async ( options ) => {
37
40
const customRegistry = options . registry as string | undefined ;
38
41
const mainnetFilter = options . mainnet as string [ ] | undefined ;
39
42
const testnetFilter = options . testnet as string [ ] | undefined ;
40
43
44
+ const jsFormat : Format = options . format === "esm" || options . format === "cjs" ? options . format : "cjs" ;
45
+
41
46
p . intro ( "graz generate" ) ;
42
47
const s = p . spinner ( ) ;
43
48
44
- // p.log.step("Cloning chain registry...");
45
49
s . start ( `Cloning chain registry` ) ;
46
50
await cloneRegistry ( customRegistry ) ;
47
51
s . stop ( "Cloned chain registry ✅" ) ;
48
52
49
- // p.log.step("Retrieving chain paths...");
50
53
s . start ( "Retrieving chain paths" ) ;
51
54
const { mainnetPaths, testnetPaths } = await getChainPaths ( { mainnetFilter, testnetFilter } ) ;
52
55
s . stop ( "Retrieved chain paths ✅" ) ;
53
56
54
- // p.log.step("Generating chain sources...");
55
57
s . start ( "Generating chain sources" ) ;
56
58
await fs . rm ( "chains/" , { recursive : true , force : true } ) ;
57
59
await pMap ( [ ...mainnetPaths , ...testnetPaths ] , makeSources , {
58
60
concurrency : Math . max ( 1 , ( os . cpus ( ) || { length : 1 } ) . length - 1 ) ,
59
61
} ) ;
60
62
s . stop ( "Generated chain sources ✅" ) ;
61
63
62
- // p.log.step("Generating chain index...");
63
64
s . start ( "Generating chain index" ) ;
64
65
await makeRootSources ( { mainnetPaths, testnetPaths } ) ;
65
66
s . stop ( "Generated chain index ✅" ) ;
66
67
68
+ s . start ( "Compiling typescript sources to javascript" ) ;
69
+ await buildJs ( jsFormat ) ;
70
+ s . stop ( "Compiled sources ✅" ) ;
71
+
67
72
p . outro ( 'Generate complete! You can import `mainnetChains` and `testnetChains` from "graz/chains". 🎉' ) ;
68
73
} ) ;
69
74
0 commit comments