1
1
import * as cp from "child_process" ;
2
- import { logger , Logger , field , time } from "@coder/logger" ;
2
+ import { field , Logger , logger , time } from "@coder/logger" ;
3
3
4
4
export interface CommandResult {
5
5
readonly exitCode : number ;
@@ -9,7 +9,9 @@ export interface CommandResult {
9
9
10
10
const execute = ( command : string , args : string [ ] = [ ] , options : cp . SpawnOptions , logger : Logger ) : Promise < CommandResult > => {
11
11
let resolve : ( result : CommandResult ) => void ;
12
- const prom = new Promise < CommandResult > ( res => resolve = res ) ;
12
+ const prom = new Promise < CommandResult > ( ( res ) : void => {
13
+ resolve = res ;
14
+ } ) ;
13
15
14
16
const stdout : string [ ] = [ ] ;
15
17
const stderr : string [ ] = [ ] ;
@@ -45,6 +47,7 @@ export type TaskFunction = (runner: Runner, ...args: any[]) => void | Promise<vo
45
47
46
48
export interface Runner {
47
49
cwd : string ;
50
+
48
51
execute ( command : string , args ?: string [ ] , env ?: object ) : Promise < CommandResult > ;
49
52
}
50
53
@@ -91,10 +94,22 @@ export const run = (name: string = process.argv[2]): void | Promise<void> => {
91
94
cwd = path ;
92
95
} ,
93
96
execute ( command : string , args : string [ ] = [ ] , env ?: object ) : Promise < CommandResult > {
94
- return execute ( command , args , {
97
+ const prom = execute ( command , args , {
95
98
cwd,
96
99
env : env as NodeJS . ProcessEnv ,
97
100
} , log ) ;
101
+
102
+ return prom . then ( ( result : CommandResult ) => {
103
+ if ( result . exitCode != 0 ) {
104
+ log . error ( "failed" ,
105
+ field ( "exitCode" , result . exitCode ) ,
106
+ field ( "stdout" , result . stdout ) ,
107
+ field ( "stderr" , result . stderr )
108
+ ) ;
109
+ }
110
+
111
+ return result ;
112
+ } ) ;
98
113
} ,
99
114
} , ...process . argv . slice ( 3 ) ) ;
100
115
0 commit comments