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

View File

@ -31,6 +31,7 @@ function run() {
redeploy_path, redeploy_path,
first_run, first_run,
port, port,
debounce,
} = config; } = config;
let redeployFile: string | undefined; let redeployFile: string | undefined;
@ -64,6 +65,7 @@ function run() {
first_run, first_run,
port, port,
postflight, postflight,
debounce,
}); });
} catch (error: any) { } catch (error: any) {
console.log( console.log(

3
dist/buncid.js vendored
View File

@ -14,7 +14,7 @@ function run() {
try { try {
const configText = fs_1.default.readFileSync(path_1.default.join(WORK_DIR, "buncid.config.json"), "utf-8"); const configText = fs_1.default.readFileSync(path_1.default.join(WORK_DIR, "buncid.config.json"), "utf-8");
const config = JSON.parse(configText); const config = JSON.parse(configText);
const { start, preflight, postflight, build, redeploy_path, first_run, port, } = config; const { start, preflight, postflight, build, redeploy_path, first_run, port, debounce, } = config;
let redeployFile; let redeployFile;
if (!redeploy_path) { if (!redeploy_path) {
const defaultRedeployPath = path_1.default.join(WORK_DIR, "REDEPLOY"); const defaultRedeployPath = path_1.default.join(WORK_DIR, "REDEPLOY");
@ -38,6 +38,7 @@ function run() {
first_run, first_run,
port, port,
postflight, postflight,
debounce,
}); });
} }
catch (error) { catch (error) {

File diff suppressed because one or more lines are too long

1
dist/types.d.ts vendored
View File

@ -6,6 +6,7 @@ export interface NodeCIConfig {
first_run?: boolean; first_run?: boolean;
port?: string | number | (string | number)[]; port?: string | number | (string | number)[];
build?: NodeCIBuild; build?: NodeCIBuild;
debounce?: number;
} }
export interface NodeCIBuild { export interface NodeCIBuild {
paradigm: "Next.JS" | "Remix"; paradigm: "Next.JS" | "Remix";

View File

@ -8,11 +8,12 @@
* @param {string | number | (string | number)[]} [param0.port] - The port to kill on rebuild * @param {string | number | (string | number)[]} [param0.port] - The port to kill on rebuild
* @param {boolean} [param0.first_run] - Whether to run the preflight on first run. Default `false` * @param {boolean} [param0.first_run] - Whether to run the preflight on first run. Default `false`
*/ */
export default function startProcess({ command, preflight, postflight, redeploy_file, port, first_run, }: { export default function startProcess({ command, preflight, postflight, redeploy_file, port, first_run, debounce, }: {
command: string; command: string;
preflight?: string[] | string; preflight?: string[] | string;
postflight?: string[] | string; postflight?: string[] | string;
redeploy_file: string; redeploy_file: string;
port?: string | number | (string | number)[]; port?: string | number | (string | number)[];
first_run?: boolean; first_run?: boolean;
debounce?: number;
}): void; }): void;

71
dist/utils/start.js vendored
View File

@ -12,6 +12,7 @@ const kill_child_1 = __importDefault(require("./kill-child"));
let childProcess = null; let childProcess = null;
const pTitle = "buncid"; const pTitle = "buncid";
process.title = pTitle; process.title = pTitle;
let timeout;
/** /**
* # Start the process * # Start the process
* @param {object} param0 * @param {object} param0
@ -22,7 +23,8 @@ process.title = pTitle;
* @param {string | number | (string | number)[]} [param0.port] - The port to kill on rebuild * @param {string | number | (string | number)[]} [param0.port] - The port to kill on rebuild
* @param {boolean} [param0.first_run] - Whether to run the preflight on first run. Default `false` * @param {boolean} [param0.first_run] - Whether to run the preflight on first run. Default `false`
*/ */
function startProcess({ command, preflight, postflight, redeploy_file, port, first_run, }) { function startProcess({ command, preflight, postflight, redeploy_file, port, first_run, debounce, }) {
const DEBOUNCE = debounce || 1000;
try { try {
if (first_run) { if (first_run) {
console.log("First Run ..."); console.log("First Run ...");
@ -35,42 +37,45 @@ function startProcess({ command, preflight, postflight, redeploy_file, port, fir
} }
console.log("Watching", redeploy_file); console.log("Watching", redeploy_file);
fs_1.default.watchFile(redeploy_file, { interval: 100 }, (curr, prev) => { fs_1.default.watchFile(redeploy_file, { interval: 100 }, (curr, prev) => {
console.log(`${console_colors_1.default.BgBlue}File Changed${console_colors_1.default.Reset}`); clearTimeout(timeout);
if (global.REDEPLOYMENTS == 0) { timeout = setTimeout(() => {
return; console.log(`${console_colors_1.default.BgBlue}File Changed${console_colors_1.default.Reset}`);
} if (global.REDEPLOYMENTS == 0) {
if (childProcess) { return;
console.log("******************************"); }
console.log(`******** ${console_colors_1.default.FgBlue}Rebuilding ${console_colors_1.default.FgMagenta}${global.REDEPLOYMENTS}${console_colors_1.default.Reset} ********`); if (childProcess) {
console.log("******************************"); console.log("******************************");
try { console.log(`******** ${console_colors_1.default.FgBlue}Rebuilding ${console_colors_1.default.FgMagenta}${global.REDEPLOYMENTS}${console_colors_1.default.Reset} ********`);
const runPreflight = (0, preflight_1.default)(preflight); console.log("******************************");
if (!runPreflight) { try {
console.log(`${console_colors_1.default.FgRed}Error:${console_colors_1.default.Reset} Preflight Failed.`); const runPreflight = (0, preflight_1.default)(preflight);
} if (!runPreflight) {
else { console.log(`${console_colors_1.default.FgRed}Error:${console_colors_1.default.Reset} Preflight Failed.`);
(0, kill_child_1.default)(childProcess, port).then((kill) => { }
if (kill) { else {
childProcess = (0, run_1.default)(command); (0, kill_child_1.default)(childProcess, port).then((kill) => {
if (postflight) { if (kill) {
const runPostflight = (0, preflight_1.default)(postflight, true); childProcess = (0, run_1.default)(command);
if (!runPostflight) { if (postflight) {
// TODO: Action to take if postflight fails const runPostflight = (0, preflight_1.default)(postflight, true);
console.log(`${console_colors_1.default.FgRed}Error:${console_colors_1.default.Reset} Postflight Failed.`); if (!runPostflight) {
// TODO: Action to take if postflight fails
console.log(`${console_colors_1.default.FgRed}Error:${console_colors_1.default.Reset} Postflight Failed.`);
}
} }
} }
} else {
else { process.exit();
process.exit(); }
} });
}); }
}
catch (error) {
console.log(`${console_colors_1.default.FgRed}Error:${console_colors_1.default.Reset} killing child processes => ${error.message}`);
process.exit();
} }
} }
catch (error) { }, DEBOUNCE);
console.log(`${console_colors_1.default.FgRed}Error:${console_colors_1.default.Reset} killing child processes => ${error.message}`);
process.exit();
}
}
}); });
} }
catch (error) { catch (error) {

View File

@ -1,6 +1,6 @@
{ {
"name": "@moduletrace/buncid", "name": "@moduletrace/buncid",
"version": "1.0.4", "version": "1.0.5",
"description": "Simple CI/CD process For Bun runtime", "description": "Simple CI/CD process For Bun runtime",
"main": "dist/index.js", "main": "dist/index.js",
"bin": { "bin": {

View File

@ -6,6 +6,7 @@ export interface NodeCIConfig {
first_run?: boolean; first_run?: boolean;
port?: string | number | (string | number)[]; port?: string | number | (string | number)[];
build?: NodeCIBuild; build?: NodeCIBuild;
debounce?: number;
} }
export interface NodeCIBuild { export interface NodeCIBuild {

View File

@ -10,6 +10,8 @@ let childProcess: ChildProcess | null = null;
const pTitle = "buncid"; const pTitle = "buncid";
process.title = pTitle; process.title = pTitle;
let timeout: any;
/** /**
* # Start the process * # Start the process
* @param {object} param0 * @param {object} param0
@ -27,6 +29,7 @@ export default function startProcess({
redeploy_file, redeploy_file,
port, port,
first_run, first_run,
debounce,
}: { }: {
command: string; command: string;
preflight?: string[] | string; preflight?: string[] | string;
@ -34,7 +37,10 @@ export default function startProcess({
redeploy_file: string; redeploy_file: string;
port?: string | number | (string | number)[]; port?: string | number | (string | number)[];
first_run?: boolean; first_run?: boolean;
debounce?: number;
}) { }) {
const DEBOUNCE = debounce || 1000;
try { try {
if (first_run) { if (first_run) {
console.log("First Run ..."); console.log("First Run ...");
@ -53,57 +59,61 @@ export default function startProcess({
console.log("Watching", redeploy_file); console.log("Watching", redeploy_file);
fs.watchFile(redeploy_file, { interval: 100 }, (curr, prev) => { fs.watchFile(redeploy_file, { interval: 100 }, (curr, prev) => {
console.log(`${colors.BgBlue}File Changed${colors.Reset}`); clearTimeout(timeout);
if (global.REDEPLOYMENTS == 0) { timeout = setTimeout(() => {
return; console.log(`${colors.BgBlue}File Changed${colors.Reset}`);
}
if (childProcess) { if (global.REDEPLOYMENTS == 0) {
console.log("******************************"); return;
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 (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) { } catch (error: any) {
console.log( console.log(