File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11const { access, constants } = require ( "fs" ) ;
2- const { resolve } = require ( "path" ) ;
2+ const path = require ( "path" ) ;
33
4- const exec = ( path ) => {
5- access ( resolve ( __dirname , `${ path } .js` ) , constants . F_OK , ( error ) => {
4+ const exec = ( scriptPath ) => {
5+ // Get the absolute path to the project root
6+ const projectRoot = path . resolve ( __dirname , '..' ) ;
7+
8+ // Resolve the script path relative to the project root
9+ const absoluteScriptPath = path . resolve ( projectRoot , scriptPath ) ;
10+ const scriptJsPath = `${ absoluteScriptPath } .js` ;
11+
12+ // Check if the compiled JS file exists
13+ access ( scriptJsPath , constants . F_OK , ( error ) => {
614 if ( error ) {
7- console . log ( `Unable to execute script ${ path } ` ) ;
15+ console . log ( `Unable to execute script ${ scriptPath } ` ) ;
16+ console . log ( `File not found: ${ scriptJsPath } ` ) ;
817 console . log ( "Remember to compile project with `npm run build`" ) ;
918 process . exit ( 1 ) ;
1019 }
20+
21+ // Execute the script
1122 ( async function ( ) {
12- await require ( path ) . run ( ) ;
23+ try {
24+ await require ( absoluteScriptPath ) . run ( ) ;
25+ } catch ( err ) {
26+ console . error ( `Error executing ${ scriptPath } :` , err ) ;
27+ process . exit ( 1 ) ;
28+ }
1329 } ) ( ) ;
1430 } ) ;
1531} ;
You can’t perform that action at this time.
0 commit comments