Archived
1
0

Add Dockerfile and some cleanup (#57)

This commit is contained in:
Anmol Sethi
2019-03-06 21:59:43 -05:00
committed by Kyle Carberry
parent ac56fcaafc
commit 17267bd801
5 changed files with 57 additions and 5 deletions

View File

@ -1,5 +1,5 @@
import * as cp from "child_process";
import { logger, Logger, field, time } from "@coder/logger";
import {field, Logger, logger, time} from "@coder/logger";
export interface CommandResult {
readonly exitCode: number;
@ -9,7 +9,9 @@ export interface CommandResult {
const execute = (command: string, args: string[] = [], options: cp.SpawnOptions, logger: Logger): Promise<CommandResult> => {
let resolve: (result: CommandResult) => void;
const prom = new Promise<CommandResult>(res => resolve = res);
const prom = new Promise<CommandResult>((res): void => {
resolve = res;
});
const stdout: string[] = [];
const stderr: string[] = [];
@ -45,6 +47,7 @@ export type TaskFunction = (runner: Runner, ...args: any[]) => void | Promise<vo
export interface Runner {
cwd: string;
execute(command: string, args?: string[], env?: object): Promise<CommandResult>;
}
@ -91,10 +94,22 @@ export const run = (name: string = process.argv[2]): void | Promise<void> => {
cwd = path;
},
execute(command: string, args: string[] = [], env?: object): Promise<CommandResult> {
return execute(command, args, {
const prom = execute(command, args, {
cwd,
env: env as NodeJS.ProcessEnv,
}, log);
return prom.then((result: CommandResult) => {
if (result.exitCode != 0) {
log.error("failed",
field("exitCode", result.exitCode),
field("stdout", result.stdout),
field("stderr", result.stderr)
);
}
return result;
});
},
}, ...process.argv.slice(3));