@@ -32,7 +32,7 @@ const cloneForBranch = async (pushDir: string, branch: string, context: Context)
32
32
signale . info ( `Cloning the branch %s from the remote repo` , branch ) ;
33
33
34
34
const url = getGitUrl ( context ) ;
35
- await execAsync ( `git -C ${ pushDir } clone --quiet --branch=${ branch } --depth=1 ${ url } .` , true ) ;
35
+ await execAsync ( `git -C ${ pushDir } clone --quiet --branch=${ branch } --depth=1 ${ url } .` , true , 'git clone' , true ) ;
36
36
} ;
37
37
38
38
const config = async ( pushDir : string ) => {
@@ -55,14 +55,14 @@ const push = async (pushDir: string, branch: string, context: Context) => {
55
55
signale . info ( 'Pushing to %s@%s' , getRepository ( context ) , branch ) ;
56
56
57
57
const url = getGitUrl ( context ) ;
58
- await execAsync ( `git -C ${ pushDir } push --quiet "${ url } " "${ branch } ":"${ branch } "` , true ) ;
58
+ await execAsync ( `git -C ${ pushDir } push --quiet "${ url } " "${ branch } ":"${ branch } "` , true , 'git push' ) ;
59
59
} ;
60
60
61
61
const cloneForBuild = async ( buildDir : string , context : Context ) => {
62
62
signale . info ( 'Cloning the working commit from the remote repo for build' ) ;
63
63
64
64
const url = getGitUrl ( context ) ;
65
- await execAsync ( `git -C ${ buildDir } clone --depth=1 ${ url } .` , true ) ;
65
+ await execAsync ( `git -C ${ buildDir } clone --depth=1 ${ url } .` , true , 'git clone' ) ;
66
66
await execAsync ( `git -C ${ buildDir } fetch origin ${ context . ref } ` ) ;
67
67
await execAsync ( `git -C ${ buildDir } checkout -qf ${ context . sha } ` ) ;
68
68
} ;
@@ -71,22 +71,21 @@ const runBuild = async (buildDir: string) => {
71
71
signale . info ( '=== Running build for release ===' ) ;
72
72
let commands = getBuildCommands ( ) ;
73
73
const buildCommand = detectBuildCommand ( buildDir ) ;
74
- const hasInstallCommand = commands . filter ( command => command . includes ( 'npm run install' ) || command . includes ( 'yarn install' ) ) ;
74
+ const hasInstallCommand = commands . filter ( command => command . includes ( 'npm run install' ) || command . includes ( 'yarn install' ) ) . length > 0 ;
75
75
if ( ! hasInstallCommand ) {
76
76
commands . push ( 'yarn install' ) ;
77
77
}
78
78
if ( typeof buildCommand === 'string' ) {
79
- commands = commands . filter ( command => buildCommand . startsWith ( `npm run ${ command } ` ) || buildCommand . startsWith ( `yarn ${ command } ` ) ) ;
79
+ commands = commands . filter ( command => ! buildCommand . startsWith ( `npm run ${ command } ` ) && ! buildCommand . startsWith ( `yarn ${ command } ` ) ) ;
80
80
commands . push ( `yarn ${ buildCommand } ` ) ;
81
81
}
82
82
if ( ! hasInstallCommand ) {
83
83
commands . push ( 'yarn install --production' ) ;
84
84
}
85
85
86
86
const current = process . cwd ( ) ;
87
- await execAsync ( `cd ${ buildDir } ` ) ;
88
87
for ( const command of commands ) {
89
- await execAsync ( command ) ;
88
+ await execAsync ( `cd ${ buildDir } && ${ command } ` ) ;
90
89
}
91
90
await execAsync ( `cd ${ current } ` ) ;
92
91
} ;
@@ -97,10 +96,18 @@ const copyFiles = async (buildDir: string, pushDir: string) => {
97
96
await execAsync ( `rsync -rl --exclude .git --delete "${ buildDir } /" ${ pushDir } ` ) ;
98
97
} ;
99
98
100
- const execAsync = ( command : string , quiet : boolean = false ) => new Promise < string > ( ( resolve , reject ) => {
99
+ const execAsync = ( command : string , quiet : boolean = false , altCommand : string | null = null , suppressError : boolean = false ) => new Promise < string > ( ( resolve , reject ) => {
100
+ if ( quiet && 'string' === typeof altCommand ) signale . info ( `Run command: ${ altCommand } ` ) ;
101
101
if ( ! quiet ) signale . info ( `Run command: ${ command } ` ) ;
102
- exec ( command + ( quiet ? ' > /dev/null 2>&1' : '' ) , ( error , stdout ) => {
103
- if ( error ) reject ( new Error ( `command ${ command } exited with code ${ error } .` ) ) ;
104
- resolve ( stdout ) ;
102
+ exec ( command + ( quiet ? ' > /dev/null 2>&1' : '' ) + ( suppressError ? ' || :' : '' ) , ( error , stdout ) => {
103
+ if ( error ) {
104
+ if ( quiet ) {
105
+ if ( 'string' === typeof altCommand ) reject ( new Error ( `command [${ altCommand } ] exited with code ${ error . code } .` ) ) ;
106
+ else reject ( new Error ( `command exited with code ${ error . code } .` ) ) ;
107
+ } else reject ( new Error ( `command [${ command } ] exited with code ${ error . code } .` ) ) ;
108
+ } else {
109
+ if ( ! quiet ) console . log ( stdout ) ;
110
+ resolve ( stdout ) ;
111
+ }
105
112
} ) ;
106
113
} ) ;
0 commit comments