@@ -56,14 +56,35 @@ const fatal = (...args: any[]) => {
5656 process . exit ( 1 ) ;
5757} ;
5858
59+ /**
60+ * Optionally strip the chain name if it ends with .json
61+ * e.g. /home/foo/bar/dev.json => dev
62+ *
63+ * @param chain
64+ */
65+ const stripChainspecJsonName = ( chain : string ) => {
66+ if ( ! chain . endsWith ( '.json' ) ) {
67+ return chain ;
68+ }
69+
70+ return path . parse ( chain . substring ( chain . lastIndexOf ( '/' ) + 1 ) ) . name ;
71+ } ;
72+
5973/**
6074 * Get chain spec
6175 *
6276 * @param image
6377 * @param chain
6478 */
6579const getChainspec = ( image : string , chain : string ) => {
66- const res = exec ( `docker run --rm ${ image } build-spec --chain=${ chain } --disable-default-bootnode` ) ;
80+ let res ;
81+ if ( chain . endsWith ( '.json' ) ) {
82+ res = exec (
83+ `docker run -v ${ chain } :/${ chain } --rm ${ image } build-spec --chain=/${ chain } --disable-default-bootnode`
84+ ) ;
85+ } else {
86+ res = exec ( `docker run --rm ${ image } build-spec --chain=${ chain } --disable-default-bootnode` ) ;
87+ }
6788
6889 let spec ;
6990
@@ -90,21 +111,14 @@ const exportParachainGenesis = (parachain: Parachain, output: string) => {
90111 const args = [ ] ;
91112
92113 if ( parachain . chain ) {
93- args . push (
94- `--chain=/app/${ typeof parachain . chain === 'string' ? parachain . chain : parachain . chain . base } -${
95- parachain . id
96- } .json`
97- ) ;
114+ args . push ( `--chain=/app/${ getChainspecName ( parachain . chain , parachain . id ) } ` ) ;
98115 }
99116
100- const res2 = exec (
101- `docker run -v $(pwd)/"${ output } ":/app --rm ${ parachain . image } export-genesis-wasm ${ args . join ( ' ' ) } `
102- ) ;
117+ const absOutput = output . startsWith ( '/' ) ? output : `$(pwd)/"${ output } "` ;
118+ const res2 = exec ( `docker run -v "${ absOutput } ":/app --rm ${ parachain . image } export-genesis-wasm ${ args . join ( ' ' ) } ` ) ;
103119 const wasm = res2 . stdout . trim ( ) ;
104120
105- const res = exec (
106- `docker run -v $(pwd)/"${ output } ":/app --rm ${ parachain . image } export-genesis-state ${ args . join ( ' ' ) } `
107- ) ;
121+ const res = exec ( `docker run -v "${ absOutput } ":/app --rm ${ parachain . image } export-genesis-state ${ args . join ( ' ' ) } ` ) ;
108122 const state = res . stdout . trim ( ) ;
109123
110124 return { state, wasm } ;
@@ -268,6 +282,17 @@ const setParachainRuntimeValue = (runtime: { [index: string]: any }, key: string
268282 runtime [ key ] = value ;
269283} ;
270284
285+ /**
286+ * Construct the parachain spec name
287+ *
288+ * @param chain
289+ * @param id
290+ */
291+ const getChainspecName = ( chain : Chain | string , id : number ) => {
292+ const chainName = typeof chain === 'string' ? chain : chain . base ;
293+ return `${ stripChainspecJsonName ( chainName ) } -${ id } .json` ;
294+ } ;
295+
271296/**
272297 * Generate parachain genesis file
273298 *
@@ -298,7 +323,7 @@ const generateParachainGenesisFile = (
298323 return fatal ( 'Missing paras[].chain.base' ) ;
299324 }
300325
301- const specname = ` ${ chain . base } - ${ id } .json` ;
326+ const specname = getChainspecName ( chain , id ) ;
302327 const filepath = path . join ( output , specname ) ;
303328
304329 checkOverrideFile ( filepath , yes ) ;
@@ -488,9 +513,7 @@ const generate = async (config: Config, { output, yes }: { output: string; yes:
488513 } ,
489514 command : [
490515 `--base-path=${ volumePath } ` ,
491- `--chain=/app/${ typeof parachain . chain === 'string' ? parachain . chain : parachain . chain . base } -${
492- parachain . id
493- } .json`,
516+ `--chain=/app/${ getChainspecName ( parachain . chain , parachain . id ) } ` ,
494517 '--ws-external' ,
495518 '--rpc-external' ,
496519 '--rpc-cors=all' ,
@@ -557,7 +580,7 @@ yargs(hideBin(process.argv))
557580 const configFile = fs . readFileSync ( configPath , 'utf8' ) ;
558581 config = YAML . parse ( configFile ) ;
559582 } catch ( e ) {
560- console . error ( 'Invalid config file:' , configPath ) ;
583+ console . error ( 'Invalid config file:' , configPath , e ) ;
561584 }
562585
563586 if ( config ) {
0 commit comments