buncid/dist/utils/run.js

38 lines
1.4 KiB
JavaScript
Raw Normal View History

2025-01-16 05:22:33 +00:00
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = run;
const child_process_1 = require("child_process");
const console_colors_1 = __importDefault(require("./console-colors"));
let redeployments = 0;
const KILL_SIGNAL = "SIGTERM";
/**
* ## Preflight Function
* @param {string} command
* @returns {ChildProcess | null}
*/
function run(command) {
console.log("\n******************************");
console.log(`****** ${console_colors_1.default.FgGreen}Starting App ...${console_colors_1.default.Reset} ******`);
console.log("******************************\n");
const startCommandArray = command.split(" ").filter((str) => str.trim());
try {
const firstCommand = startCommandArray.shift();
if (!firstCommand) {
throw new Error("No Starting Command Found in command string!");
}
2025-01-16 08:28:46 +00:00
let newChildProcess = (0, child_process_1.spawn)(firstCommand, startCommandArray, {
2025-01-16 05:22:33 +00:00
stdio: "inherit",
killSignal: KILL_SIGNAL,
});
redeployments++;
2025-01-16 08:28:46 +00:00
return newChildProcess;
2025-01-16 05:22:33 +00:00
}
catch (error) {
console.log(`${console_colors_1.default.FgRed}Error:${console_colors_1.default.Reset} running start command => ${error.message}`);
return null;
}
}