2025-01-16 05:22:33 +00:00
|
|
|
import { spawn, ChildProcess } from "child_process";
|
|
|
|
import colors from "./console-colors";
|
|
|
|
|
|
|
|
const KILL_SIGNAL: NodeJS.Signals | number = "SIGTERM";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ## Preflight Function
|
|
|
|
* @param {string} command
|
|
|
|
* @returns {ChildProcess | null}
|
|
|
|
*/
|
|
|
|
export default function run(command: string): ChildProcess | null {
|
|
|
|
console.log("\n******************************");
|
|
|
|
console.log(
|
|
|
|
`****** ${colors.FgGreen}Starting App ...${colors.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 = spawn(firstCommand, startCommandArray, {
|
2025-01-16 05:22:33 +00:00
|
|
|
stdio: "inherit",
|
|
|
|
killSignal: KILL_SIGNAL,
|
|
|
|
});
|
|
|
|
|
2025-01-22 11:31:32 +00:00
|
|
|
global.REDEPLOYMENTS = global.REDEPLOYMENTS + 1;
|
2025-01-16 05:22:33 +00:00
|
|
|
|
2025-01-16 08:28:46 +00:00
|
|
|
return newChildProcess;
|
2025-01-16 05:22:33 +00:00
|
|
|
} catch (error: any) {
|
|
|
|
console.log(
|
|
|
|
`${colors.FgRed}Error:${colors.Reset} running start command => ${error.message}`
|
|
|
|
);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|