Add error message from subcommands

This commit is contained in:
Michaël Lemaire 2021-09-06 00:16:44 +02:00
parent de06f0839e
commit 08995dda60

View file

@ -49,10 +49,23 @@ export class ProjectNormalizer {
);
}
async run(...cmd: string[]): Promise<string> {
const p = this.sys.run({ cmd, stdout: "piped", stderr: "piped" });
const [status, stdout, stderr] = await Promise.all([
p.status(),
p.output(),
p.stderrOutput(),
]);
if (status.success) {
return new TextDecoder().decode(stdout);
} else {
console.error(new TextDecoder().decode(stderr));
throw new Error(`Command failed: ${cmd.join(" ")}`);
}
}
async formatPath(path: string) {
await this.sys.run({
cmd: ["./run", "fmt", "-q", path],
}).status();
await this.run("./run", "fmt", "-q", path);
}
async updateRunScript() {
@ -84,11 +97,7 @@ export class ProjectNormalizer {
}
async updateDenoDefs() {
const process = this.sys.run({
cmd: ["./run", "types"],
stdout: "piped",
});
const defs = new TextDecoder("utf-8").decode(await process.output());
const defs = await this.run("./run", "types");
await this.sys.writeTextFile("deno.d.ts", defs);
}