UNPKG

@berenddeboer/nx-sst

Version:
73 lines 2.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LARGE_BUFFER = exports.executorPropKeys = void 0; exports.parseArgs = parseArgs; exports.createCommand = createCommand; exports.runCommandProcess = runCommandProcess; const child_process_1 = require("child_process"); const devkit_1 = require("@nx/devkit"); exports.executorPropKeys = ["stacks"]; exports.LARGE_BUFFER = 1024 * 1000000; function parseArgs(options) { const keys = Object.keys(options); return keys .filter((prop) => exports.executorPropKeys.indexOf(prop) < 0) .reduce((acc, key) => ((acc[key] = options[key]), acc), {}); } function createCommand(command, options) { let sst; if (options.polyfills && options.polyfills.length) { const a = ["node"]; options.polyfills.forEach((pf) => { a.push(`-r ${pf}`); }); a.push(`${devkit_1.workspaceRoot}/node_modules/sst/cli/sst.js`); sst = a.join(" "); } else { sst = "npx sst"; } const commands = [`${sst} ${command}`]; for (const arg in options.parseArgs) { commands.push(`--${arg} ${options.parseArgs[arg]}`); } if (options.stacks && options.stacks.length) { commands.push(options.stacks.join(" ")); } return commands.join(" "); } function runCommandProcess(command, cwd) { return new Promise((resolve) => { devkit_1.logger.debug(`Executing command: ${command}`); const childProcess = (0, child_process_1.exec)(command, { maxBuffer: exports.LARGE_BUFFER, env: process.env, cwd: cwd, }); // Ensure the child process is killed when the parent exits const processExitListener = () => childProcess.kill(); process.on("exit", processExitListener); process.on("SIGTERM", processExitListener); process.stdin.on("data", (data) => { childProcess.stdin.write(data); childProcess.stdin.end(); }); childProcess.stdout.on("data", (data) => { process.stdout.write(data); }); childProcess.stderr.on("data", (err) => { process.stderr.write(err); }); childProcess.on("close", (code) => { if (code === 0) { resolve(true); } else { resolve(false); } process.removeListener("exit", processExitListener); process.stdin.removeListener("data", processExitListener); }); }); } //# sourceMappingURL=executor.util.js.map