@@ -7,43 +7,44 @@ import { bsc_exe, rescript_exe } from "./common/bins.js";
77
88const  args  =  process . argv . slice ( 2 ) ; 
99
10- const  firstPositionalArgIndex  =  args . findIndex ( arg  =>  ! arg . startsWith ( "-" ) ) ; 
11- 
12- try  { 
13-   if  ( firstPositionalArgIndex  !==  - 1 )  { 
14-     const  subcommand  =  args [ firstPositionalArgIndex ] ; 
15-     const  subcommandWithArgs  =  args . slice ( firstPositionalArgIndex ) ; 
16- 
17-     switch  ( subcommand )  { 
18-       case  "build" :
19-       case  "watch" :
20-       case  "clean" :
21-       case  "compiler-args" :
22-       case  "format" :
23-         child_process . execFileSync ( 
24-           rescript_exe , 
25-           [ ...subcommandWithArgs ,  "--bsc-path" ,  bsc_exe ] , 
26-           { 
27-             stdio : "inherit" , 
28-           } , 
29-         ) ; 
30-         break ; 
31-       default :
32-         child_process . execFileSync ( rescript_exe ,  [ ...args ] ,  { 
33-           stdio : "inherit" , 
34-         } ) ; 
35-         break ; 
36-     } 
37-   }  else  { 
38-     // no subcommand means build subcommand 
39-     child_process . execFileSync ( rescript_exe ,  [ ...args ,  "--bsc-path" ,  bsc_exe ] ,  { 
10+ /** 
11+  * @param  {string[] } cmdArgs 
12+  */ 
13+ function  execRescript ( cmdArgs )  { 
14+   console . log ( cmdArgs ) 
15+   try  { 
16+     child_process . execFileSync ( rescript_exe ,  cmdArgs ,  { 
4017      stdio : "inherit" , 
4118    } ) ; 
19+   }  catch  ( err )  { 
20+     if  ( err . status  !==  undefined )  { 
21+       process . exit ( err . status ) ;  // Pass through the exit code 
22+     }  else  { 
23+       process . exit ( 1 ) ;  // Generic error 
24+     } 
4225  } 
43- }  catch  ( err )  { 
44-   if  ( err . status  !==  undefined )  { 
45-     process . exit ( err . status ) ;  // Pass through the exit code 
46-   }  else  { 
47-     process . exit ( 1 ) ;  // Generic error 
26+ } 
27+ 
28+ const  firstPositionalArgIndex  =  args . findIndex ( arg  =>  ! arg . startsWith ( "-" ) ) ; 
29+ 
30+ if  ( firstPositionalArgIndex  !==  - 1 )  { 
31+   const  subcommand  =  args [ firstPositionalArgIndex ] ; 
32+   const  subcommandWithArgs  =  args . slice ( firstPositionalArgIndex ) ; 
33+ 
34+ 
35+   switch  ( subcommand )  { 
36+     case  "build" :
37+     case  "watch" :
38+     case  "clean" :
39+     case  "compiler-args" :
40+     case  "format" :
41+       execRescript ( [ ...subcommandWithArgs ,  "--bsc-path" ,  bsc_exe ] ) ; 
42+       break ; 
43+     default :
44+       execRescript ( args ) ; 
45+       break ; 
4846  } 
47+ }  else  { 
48+   // no subcommand means build subcommand 
49+   execRescript ( [ ...args ,  "--bsc-path" ,  bsc_exe ] ) ; 
4950} 
0 commit comments