@@ -6,6 +6,8 @@ import path from 'path';
66
77import { assert } from '@polkadot/util' ;
88
9+ import { packageInfo } from '../packageInfo' ;
10+
911export function writeFile ( dest : string , generator : ( ) => string , noLog ?: boolean ) : void {
1012 ! noLog && console . log ( `${ dest } \n\tGenerating` ) ;
1113
@@ -23,12 +25,17 @@ export function writeFile (dest: string, generator: () => string, noLog?: boolea
2325}
2426
2527export function readTemplate ( template : string ) : string {
28+ // Inside the api repo itself, it will be 'auto'
29+ const rootDir = packageInfo . path === 'auto'
30+ ? path . join ( __dirname , '..' )
31+ : packageInfo . path ;
32+
2633 // NOTE With cjs in a subdir, search one lower as well
27- const file = [ '.. /templates' , '../ ../templates' ]
28- . map ( ( p ) => path . join ( __dirname , p , `${ template } .hbs` ) )
34+ const file = [ './templates' , '../templates' ]
35+ . map ( ( p ) => path . join ( rootDir , p , `${ template } .hbs` ) )
2936 . find ( ( p ) => fs . existsSync ( p ) ) ;
3037
31- assert ( file , `Unable to locate ${ template } .hbs from ${ __dirname } ` ) ;
38+ assert ( file , `Unable to locate ${ template } .hbs from ${ rootDir } ` ) ;
3239
3340 return fs . readFileSync ( file ) . toString ( ) ;
3441}
0 commit comments