@@ -66,7 +66,7 @@ type Warning = {
6666 warning : string
6767}
6868
69- async function run_generator ( output_dir : string , moduleName : string , elm_source : string , flags : any ) {
69+ async function run_generator ( output_dir : string , moduleName : string , elm_source : string , flags : any ) : Promise < void > {
7070 eval ( elm_source )
7171
7272 const promise = new Promise < { path : string ; contents : string ; warnings : Warning [ ] } [ ] > ( ( resolve , reject ) => {
@@ -78,7 +78,7 @@ async function run_generator(output_dir: string, moduleName: string, elm_source:
7878 `Module ${ moduleName } not found in compile Elm code. Available modules are: ${ JSON . stringify ( this . Elm ) } `
7979 )
8080 )
81- return 1
81+ process . exit ( 1 )
8282 }
8383
8484 // @ts -ignore
@@ -158,11 +158,11 @@ async function run_generator(output_dir: string, moduleName: string, elm_source:
158158 }
159159 }
160160 console . error ( formatted )
161- return 1
161+ process . exit ( 1 )
162162 }
163163}
164164
165- function generate ( debug : boolean , elm_file : string , moduleName : string , output_dir : string , cwd : string , flags : any ) {
165+ async function generate ( debug : boolean , elm_file : string , moduleName : string , output_dir : string , cwd : string , flags : any ) : Promise < void > {
166166 try {
167167 const data = elm_compiler . compileToStringSync ( [ elm_file ] , {
168168 cwd : cwd ,
@@ -171,7 +171,7 @@ function generate(debug: boolean, elm_file: string, moduleName: string, output_d
171171 } )
172172
173173 // @ts -ignore
174- return new run_generator ( output_dir , moduleName , data . toString ( ) , flags )
174+ await new run_generator ( output_dir , moduleName , data . toString ( ) , flags )
175175 } catch ( error : unknown ) {
176176 // This is generally an elm make error from the elm_compiler
177177 console . log ( error )
@@ -560,7 +560,7 @@ export type Options = {
560560
561561export async function run ( elmFile : string , options : Options ) {
562562 const moduleName = path . parse ( elmFile ) . name
563- generate ( options . debug , elmFile , moduleName , options . output , options . cwd || "." , options . flags )
563+ await generate ( options . debug , elmFile , moduleName , options . output , options . cwd || "." , options . flags )
564564}
565565
566566export type CliOptions = {
@@ -615,7 +615,7 @@ function fileToFlags(filename: string) {
615615 return parsed
616616}
617617
618- export async function run_generation_from_cli ( desiredElmFile : string | null , options : CliOptions ) {
618+ export async function run_generation_from_cli ( desiredElmFile : string | null , options : CliOptions ) : Promise < void > {
619619 let elmFile = "Generate.elm"
620620 let cwd = "./codegen"
621621
@@ -690,16 +690,16 @@ export async function run_generation_from_cli(desiredElmFile: string | null, opt
690690 if ( options . watch ) {
691691 // clear(output)
692692
693- generate ( options . debug , elmFile , moduleName , output , cwd , flags )
694- Chokidar . watch ( path . join ( cwd , "**" , "*.elm" ) , { ignored : path . join ( output , "**" ) } ) . on ( "all" , ( event , path ) => {
693+ await generate ( options . debug , elmFile , moduleName , output , cwd , flags )
694+ Chokidar . watch ( path . join ( cwd , "**" , "*.elm" ) , { ignored : path . join ( output , "**" ) } ) . on ( "all" , async ( event , path ) => {
695695 if ( event === "change" ) {
696696 console . log ( `\n${ path } changed, regenerating` )
697- generate ( options . debug , elmFile , moduleName , output , cwd , flags )
697+ await generate ( options . debug , elmFile , moduleName , output , cwd , flags )
698698 }
699699 } )
700700 } else {
701701 // skipping clearing files because in my test case it was failing with permission denied all the time.
702702 // clear(output)
703- generate ( options . debug , elmFile , moduleName , output , cwd , flags )
703+ await generate ( options . debug , elmFile , moduleName , output , cwd , flags )
704704 }
705705}
0 commit comments