ducki
Version:
Simple utility scripts for exporting KiCad images.
64 lines (48 loc) • 1.73 kB
text/typescript
import { spawnSync } from "child_process";
export class RunResult {
readonly
readonly
readonly
readonly
constructor(progname: string, args: Array<string>, status: null | number, stdout: string | Buffer, stderr: string | Buffer) {
this.
this.
this.
this.
}
get cmd(): string { return this.
get stderr(): string | null {
return this._stderr.toString() || null;
}
get _stderr(): string | Buffer {
return this.
}
get stdout(): string {
return this._stdout.toString();
}
get _stdout(): string | Buffer {
return this.
}
get status(): null | number { return this.
get ok(): boolean {
return (this.
}
assertOk(message?: string): void {
if (!this.ok) {
throw new Error(message || `failed to run: ${ this.
}
}
};
export function run(progname: string, args?: Array<string>, currentWorkingDirectory?: string): RunResult {
if (args == null) { args = [ ]; }
const options: any = { };
if (currentWorkingDirectory) { options.cwd = currentWorkingDirectory; }
const child = spawnSync(progname, args, options);
const result = new RunResult(progname, args, child.status, child.stdout, child.stderr);
if (child.error) {
const error = child.error;
(<any>error).result = result;
throw error;
}
return result;
}