11import chalk from 'chalk' ;
2- import * as cp from 'child_process' ;
2+ import { SpawnOptions , spawn } from 'child_process' ;
33import logSymbols from 'log-symbols' ;
44import { env } from './env' ;
55
@@ -20,29 +20,22 @@ function splitCommandAndArgs(command: string): Command {
2020// Wrap spawn in a promise
2121function asyncSpawn (
2222 command : string ,
23- args ? : ReadonlyArray < string > ,
24- options ?: cp . SpawnOptionsWithoutStdio
23+ args : ReadonlyArray < string > ,
24+ options : SpawnOptions
2525) : Promise < number | null > {
2626 return new Promise ( function ( resolve , reject ) {
2727 if ( env . debug ) {
2828 const commandWithArgs = `${ command } ${ args ?. join ( ' ' ) } ` ;
2929 const optionsStr = JSON . stringify ( options ) ;
3030 console . log (
31- chalk . white (
32- `ℹ️ Executing command: ${ commandWithArgs } with options: ${ optionsStr } `
31+ logSymbols . info ,
32+ chalk . whiteBright (
33+ `Executing command: ${ commandWithArgs } with options: ${ optionsStr } `
3334 )
3435 ) ;
3536 }
3637
37- const process = cp . spawn ( command , args , options ) ;
38-
39- process . stdout . on ( 'data' , ( data ) => {
40- console . log ( logSymbols . info , chalk . white ( data . toString ( ) ) ) ;
41- } ) ;
42-
43- process . stderr . on ( 'data' , ( data ) => {
44- console . error ( logSymbols . error , chalk . red ( data . toString ( ) ) ) ;
45- } ) ;
38+ const process = spawn ( command , args , options ) ;
4639
4740 process . on ( 'exit' , function ( code ) {
4841 if ( code !== 0 ) reject ( code ) ;
@@ -57,15 +50,23 @@ function asyncSpawn(
5750
5851function runCommandString (
5952 command : string ,
60- workDir ? : string
53+ workDir : string
6154) : Promise < number | null > {
62- console . log ( logSymbols . info , chalk . white ( `Running command: ${ command } ` ) ) ;
55+ console . log (
56+ logSymbols . info ,
57+ chalk . whiteBright ( `Running command: ${ command } ` )
58+ ) ;
6359 const cmd = splitCommandAndArgs ( command ) ;
64- return asyncSpawn ( cmd . command , cmd . args , { cwd : workDir } ) ;
60+ return asyncSpawn ( cmd . command , cmd . args , {
61+ cwd : workDir ,
62+ stdio : [ 'pipe' , 'inherit' , 'inherit' ] ,
63+ } ) ;
6564}
6665
67- export async function runCLICommand ( commandStr : Array < string > ) {
68- const workDir = process . env . BITBUCKET_CLONE_DIR ;
66+ export async function runCLICommand (
67+ commandStr : Array < string > ,
68+ workDir : string
69+ ) {
6970 console . log ( logSymbols . info , chalk . white ( `Running commands in ${ workDir } ` ) ) ;
7071
7172 for ( const cmd of commandStr ) {
0 commit comments