Updates
This commit is contained in:
+58
-48
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user