@routineless/nx-aws-cdk
Version:
Nx plugin for AWS CDK
57 lines • 2.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.runCommand = exports.runCommandsInParralel = void 0;
const child_process_1 = require("child_process");
const logger_1 = require("../utils/logger");
const runCommandsInParralel = async (commands) => {
const promises = commands.map((command) => (0, exports.runCommand)(command));
return Promise.all(promises);
};
exports.runCommandsInParralel = runCommandsInParralel;
const runCommand = async (executionCommand, options) => {
const { command, cwd } = executionCommand;
logger_1.logger.debug(`Executing command: ${command}`);
if (cwd) {
logger_1.logger.debug(`Working directory: ${cwd}`);
}
let stdio = [process.stdin, process.stdout, process.stderr];
if (options?.stdio) {
stdio = options.stdio;
}
const childProcess = (0, child_process_1.spawn)(command, {
shell: true,
env: process.env,
cwd: cwd,
stdio: stdio,
});
const processExitListener = () => childProcess.kill();
process.on('exit', processExitListener);
process.on('SIGTERM', processExitListener);
return onExit(childProcess, processExitListener);
};
exports.runCommand = runCommand;
const onExit = (childProcess, processExitListener) => {
return new Promise((resolve, reject) => {
// I wanted to debug what command was finished here, maybe I can use childProcess to get this info
// othervise I will propagate command to this function
const exitHandler = (code, signal) => {
logger_1.logger.debug(`Finished ${childProcess.spawnargs.join(' ')} command execution: ${code}, ${signal}`);
process.removeListener('exit', processExitListener);
if (code === 0) {
resolve({ code, signal });
}
else if (!code) {
reject(new Error(`Exit with signal: ${signal}`));
}
else {
reject(new Error(`Exit with error code: ${code}`));
}
};
childProcess.once('close', exitHandler);
childProcess.once('error', (err) => {
process.removeListener('exit', processExitListener);
reject(err);
});
});
};
//# sourceMappingURL=executors.js.map