// // Promise wrapper around Nova's Process API. Nova has no synchronous exec, so // everything that shells out (git, mostly) funnels through here. // const log = require("./log.js"); function exec(command, args, options = {}) { return new Promise((resolve) => { let stdout = ""; let stderr = ""; let process; try { process = new Process(command, { args: args, cwd: options.cwd, env: options.env, shell: false, stdio: "pipe", }); } catch (error) { resolve({ status: -1, stdout: "", stderr: String(error) }); return; } process.onStdout((line) => { stdout += line; }); process.onStderr((line) => { stderr += line; }); process.onDidExit((status) => { log.debug(`exec ${command} ${(args || []).join(" ")} -> ${status}`); resolve({ status: status, stdout: stdout, stderr: stderr }); }); try { process.start(); } catch (error) { resolve({ status: -1, stdout: "", stderr: String(error) }); } }); } /** Runs a command and resolves to trimmed stdout, or null on any failure. */ async function output(command, args, options) { const result = await exec(command, args, options); if (result.status !== 0) return null; return result.stdout.trim(); } exports.exec = exec; exports.output = output;