11import { blue , magenta } from 'ansis' ;
22import * as childProcess from 'child_process' ;
3+ import { execFile as execFileCb } from 'child_process' ;
34import * as log from 'fancy-log' ;
45import { task } from 'gulp' ;
56import { resolve } from 'path' ;
@@ -8,6 +9,7 @@ import { samplePath } from '../config';
89import { containsPackageJson , getDirs } from '../util/task-helpers' ;
910
1011const exec = promisify ( childProcess . exec ) ;
12+ const execFile = promisify ( execFileCb ) ;
1113
1214async function executeNpmScriptInSamples (
1315 script : string ,
@@ -78,12 +80,17 @@ async function executeNPMScriptInDirectory(
7880 const dirName = dir . replace ( resolve ( __dirname , '../../../' ) , '' ) ;
7981 log . info ( `Running ${ blue ( script ) } in ${ magenta ( dirName ) } ` ) ;
8082 try {
81- const result = await exec (
82- `${ script } --prefix ${ dir } ${ appendScript ? '-- ' + appendScript : '' } ` ,
83- ) ;
84- // const result = await exec(`npx npm-check-updates -u`, {
85- // cwd: join(process.cwd(), dir),
86- // });
83+ // Split the script into command and arguments
84+ const scriptParts = script . split ( ' ' ) . filter ( Boolean ) ;
85+ const command = scriptParts [ 0 ] ;
86+ const args = scriptParts . slice ( 1 ) ;
87+ // Add --prefix and dir
88+ args . push ( '--prefix' , dir ) ;
89+ // If appendScript is provided, split and append
90+ if ( appendScript ) {
91+ args . push ( '--' , ...appendScript . split ( ' ' ) . filter ( Boolean ) ) ;
92+ }
93+ const result = await execFile ( command , args ) ;
8794
8895 log . info ( `Finished running ${ blue ( script ) } in ${ magenta ( dirName ) } ` ) ;
8996 if ( result . stderr ) {
0 commit comments