This commit is contained in:
Benjamin Toby
2025-02-03 14:21:32 +01:00
parent 619afc8303
commit 1e57cdbc1d
9 changed files with 106 additions and 85 deletions
+58 -48
View File
@@ -10,6 +10,8 @@ let childProcess: ChildProcess | null = null;
const pTitle = "buncid";
process.title = pTitle;
let timeout: any;
/**
* # Start the process
* @param {object} param0
@@ -27,6 +29,7 @@ export default function startProcess({
redeploy_file,
port,
first_run,
debounce,
}: {
command: string;
preflight?: string[] | string;
@@ -34,7 +37,10 @@ export default function startProcess({
redeploy_file: string;
port?: string | number | (string | number)[];
first_run?: boolean;
debounce?: number;
}) {
const DEBOUNCE = debounce || 1000;
try {
if (first_run) {
console.log("First Run ...");
@@ -53,57 +59,61 @@ export default function startProcess({
console.log("Watching", redeploy_file);
fs.watchFile(redeploy_file, { interval: 100 }, (curr, prev) => {
console.log(`${colors.BgBlue}File Changed${colors.Reset}`);
clearTimeout(timeout);
if (global.REDEPLOYMENTS == 0) {
return;
}
timeout = setTimeout(() => {
console.log(`${colors.BgBlue}File Changed${colors.Reset}`);
if (childProcess) {
console.log("******************************");
console.log(
`******** ${colors.FgBlue}Rebuilding ${colors.FgMagenta}${global.REDEPLOYMENTS}${colors.Reset} ********`
);
console.log("******************************");
try {
const runPreflight = preflightFn(preflight);
if (!runPreflight) {
console.log(
`${colors.FgRed}Error:${colors.Reset} Preflight Failed.`
);
} else {
killChild(childProcess, port).then((kill) => {
if (kill) {
childProcess = run(command);
if (postflight) {
const runPostflight = preflightFn(
postflight,
true
);
if (!runPostflight) {
// TODO: Action to take if postflight fails
console.log(
`${colors.FgRed}Error:${colors.Reset} Postflight Failed.`
);
}
}
} else {
process.exit();
}
});
}
} catch (error: any) {
console.log(
`${colors.FgRed}Error:${colors.Reset} killing child processes => ${error.message}`
);
process.exit();
if (global.REDEPLOYMENTS == 0) {
return;
}
}
if (childProcess) {
console.log("******************************");
console.log(
`******** ${colors.FgBlue}Rebuilding ${colors.FgMagenta}${global.REDEPLOYMENTS}${colors.Reset} ********`
);
console.log("******************************");
try {
const runPreflight = preflightFn(preflight);
if (!runPreflight) {
console.log(
`${colors.FgRed}Error:${colors.Reset} Preflight Failed.`
);
} else {
killChild(childProcess, port).then((kill) => {
if (kill) {
childProcess = run(command);
if (postflight) {
const runPostflight = preflightFn(
postflight,
true
);
if (!runPostflight) {
// TODO: Action to take if postflight fails
console.log(
`${colors.FgRed}Error:${colors.Reset} Postflight Failed.`
);
}
}
} else {
process.exit();
}
});
}
} catch (error: any) {
console.log(
`${colors.FgRed}Error:${colors.Reset} killing child processes => ${error.message}`
);
process.exit();
}
}
}, DEBOUNCE);
});
} catch (error: any) {
console.log(