1
1
import { blue , magenta } from 'ansis' ;
2
2
import * as childProcess from 'child_process' ;
3
+ import { execFile as execFileCb } from 'child_process' ;
3
4
import * as log from 'fancy-log' ;
4
5
import { task } from 'gulp' ;
5
6
import { resolve } from 'path' ;
@@ -8,6 +9,7 @@ import { samplePath } from '../config';
8
9
import { containsPackageJson , getDirs } from '../util/task-helpers' ;
9
10
10
11
const exec = promisify ( childProcess . exec ) ;
12
+ const execFile = promisify ( execFileCb ) ;
11
13
12
14
async function executeNpmScriptInSamples (
13
15
script : string ,
@@ -78,12 +80,17 @@ async function executeNPMScriptInDirectory(
78
80
const dirName = dir . replace ( resolve ( __dirname , '../../../' ) , '' ) ;
79
81
log . info ( `Running ${ blue ( script ) } in ${ magenta ( dirName ) } ` ) ;
80
82
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 ) ;
87
94
88
95
log . info ( `Finished running ${ blue ( script ) } in ${ magenta ( dirName ) } ` ) ;
89
96
if ( result . stderr ) {
0 commit comments