11import * as cp from "child_process" ;
2- import { logger , Logger , field , time } from "@coder/logger" ;
2+ import { field , Logger , logger , time } from "@coder/logger" ;
33
44export interface CommandResult {
55 readonly exitCode : number ;
@@ -9,7 +9,9 @@ export interface CommandResult {
99
1010const execute = ( command : string , args : string [ ] = [ ] , options : cp . SpawnOptions , logger : Logger ) : Promise < CommandResult > => {
1111 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+ } ) ;
1315
1416 const stdout : string [ ] = [ ] ;
1517 const stderr : string [ ] = [ ] ;
@@ -45,6 +47,7 @@ export type TaskFunction = (runner: Runner, ...args: any[]) => void | Promise<vo
4547
4648export interface Runner {
4749 cwd : string ;
50+
4851 execute ( command : string , args ?: string [ ] , env ?: object ) : Promise < CommandResult > ;
4952}
5053
@@ -91,10 +94,22 @@ export const run = (name: string = process.argv[2]): void | Promise<void> => {
9194 cwd = path ;
9295 } ,
9396 execute ( command : string , args : string [ ] = [ ] , env ?: object ) : Promise < CommandResult > {
94- return execute ( command , args , {
97+ const prom = execute ( command , args , {
9598 cwd,
9699 env : env as NodeJS . ProcessEnv ,
97100 } , 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+ } ) ;
98113 } ,
99114 } , ...process . argv . slice ( 3 ) ) ;
100115
0 commit comments