Add error message from subcommands
This commit is contained in:
parent
de06f0839e
commit
08995dda60
1 changed files with 17 additions and 8 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue