alwaysai
Version:
The alwaysAI command-line interface (CLI)
53 lines • 1.97 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.runForeground = void 0;
const child_process_1 = require("child_process");
const signalExit = require("signal-exit");
const rKill = require("tree-kill");
const alwayscli_1 = require("@alwaysai/alwayscli");
const environment_1 = require("../../../environment");
const logger_1 = require("../../logger");
async function runForeground(cmd) {
var _a;
const optString = cmd.args ? cmd.args.join(' ') : '';
logger_1.logger.debug(`${cmd.exe} ${optString}`);
const childProcess = (0, child_process_1.spawn)(cmd.exe, (_a = cmd.args) !== null && _a !== void 0 ? _a : [], {
cwd: cmd.cwd,
stdio: 'inherit'
});
// Kill child when parent exits
signalExit(() => {
if (environment_1.ALWAYSAI_OS_PLATFORM === 'darwin') {
childProcess.kill('SIGINT');
// ensures the main process gets killed by the correct signal - this will only activate with a ctrl + c
// when it hits the siginit it will then activate the on exit signal and finish
process.on('SIGINT', () => {
if (childProcess.pid) {
rKill(childProcess.pid, 'SIGINT', (error) => {
if (error) {
throw new alwayscli_1.CliTerseError(`Failed to kill child process {error.name} {error.message}`);
}
});
}
});
}
else {
childProcess.kill();
}
});
return await new Promise((resolve, reject) => {
childProcess.on('error', (err) => {
reject(err);
});
childProcess.on('exit', (code) => {
if (code) {
resolve(code);
}
else {
resolve();
}
});
});
}
exports.runForeground = runForeground;
//# sourceMappingURL=run-foreground.js.map