buncid/utils/run.ts

44 lines
1.2 KiB
TypeScript
Raw Normal View History

2025-01-16 05:22:33 +00:00
import { spawn, ChildProcess } from "child_process";
import colors from "./console-colors";
let redeployments = 0;
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,
});
redeployments++;
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;
}
}