UNPKG

@tobiastengler/create-relay-app

Version:

Easy configuration of Relay for existing projects

29 lines (28 loc) 926 B
import { spawn } from "child_process"; import { EOL } from "os"; export class CommandRunner { run(command, args, cwd) { return new Promise((resolve, reject) => { const child = spawn(command, args, { cwd: cwd, shell: true, }); let errorMsg = ""; child.stderr.setEncoding("utf-8"); child.stderr.on("data", (data) => { errorMsg += data; }); child.on("close", (code) => { if (code !== 0) { let output = `Command \"${command} ${args.join(" ")}\" failed`; if (!!errorMsg) { output += EOL + EOL + " " + errorMsg.split(EOL).join(EOL + " "); } reject(output); return; } resolve(); }); }); } }