UNPKG

@techdocs/cli

Version:

Utility CLI for managing TechDocs sites in Backstage.

59 lines (55 loc) 1.48 kB
'use strict'; var child_process = require('child_process'); const run = async (name, args = [], options = {}) => { const { stdoutLogFunc, stderrLogFunc } = options; const env = { ...process.env, FORCE_COLOR: "true", ...options.env ?? {} }; const stdio = [ "inherit", stdoutLogFunc ? "pipe" : "inherit", stderrLogFunc ? "pipe" : "inherit" ]; const childProcess = child_process.spawn(name, args, { stdio, ...options, env }); if (stdoutLogFunc && childProcess.stdout) { childProcess.stdout.on("data", stdoutLogFunc); } if (stderrLogFunc && childProcess.stderr) { childProcess.stderr.on("data", stderrLogFunc); } return childProcess; }; async function waitForSignal(childProcesses) { const promises = []; for (const signal of ["SIGINT", "SIGTERM"]) { process.on(signal, () => { childProcesses.forEach((childProcess) => { childProcess.kill(); }); }); } childProcesses.forEach((childProcess) => { if (typeof childProcess.exitCode === "number") { if (childProcess.exitCode) { throw new Error(`Non zero exit code from child process`); } return; } promises.push( new Promise((resolve, reject) => { childProcess.once("error", reject); childProcess.once("exit", resolve); }) ); }); await Promise.all(promises); } exports.run = run; exports.waitForSignal = waitForSignal; //# sourceMappingURL=run.cjs.js.map