2025-01-16 07:16:23 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2025-01-16 05:22:33 +00:00
|
|
|
import fs from "fs";
|
|
|
|
import path from "path";
|
|
|
|
import colors from "./utils/console-colors";
|
|
|
|
import startProcess from "./utils/start";
|
|
|
|
import type { NodeCIConfig } from "./types";
|
2023-10-29 07:35:26 +00:00
|
|
|
|
|
|
|
const WORK_DIR = process.cwd();
|
|
|
|
|
2023-11-01 05:01:17 +00:00
|
|
|
function run() {
|
|
|
|
try {
|
|
|
|
const configText = fs.readFileSync(
|
|
|
|
path.join(WORK_DIR, "nodecid.config.json"),
|
|
|
|
"utf-8"
|
|
|
|
);
|
|
|
|
|
2025-01-16 05:22:33 +00:00
|
|
|
const config: NodeCIConfig = JSON.parse(configText);
|
2023-11-01 05:01:17 +00:00
|
|
|
|
2023-11-06 20:06:33 +00:00
|
|
|
const {
|
|
|
|
start,
|
|
|
|
preflight,
|
|
|
|
postflight,
|
|
|
|
build,
|
|
|
|
redeploy_path,
|
|
|
|
first_run,
|
|
|
|
port,
|
|
|
|
} = config;
|
2023-11-01 05:01:17 +00:00
|
|
|
|
|
|
|
/** @type {string | undefined} */
|
|
|
|
let redeployFile;
|
|
|
|
|
|
|
|
if (!redeploy_path) {
|
|
|
|
const defaultRedeployPath = path.join(WORK_DIR, "REDEPLOY");
|
|
|
|
const checkExistingPath = fs.existsSync(defaultRedeployPath);
|
|
|
|
|
|
|
|
if (!checkExistingPath) {
|
|
|
|
fs.writeFileSync(
|
|
|
|
defaultRedeployPath,
|
|
|
|
Date.now().toString(),
|
|
|
|
"utf-8"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
redeployFile = path.join(WORK_DIR, "REDEPLOY");
|
|
|
|
} else {
|
|
|
|
redeployFile = path.resolve(WORK_DIR, redeploy_path);
|
2023-10-29 10:49:04 +00:00
|
|
|
}
|
|
|
|
|
2023-11-01 05:01:17 +00:00
|
|
|
if (!redeployFile) throw new Error("Redeploy file not found!");
|
2023-10-29 07:35:26 +00:00
|
|
|
|
2023-11-01 05:01:17 +00:00
|
|
|
startProcess({
|
|
|
|
command: start,
|
|
|
|
preflight,
|
|
|
|
redeploy_file: redeployFile,
|
|
|
|
first_run,
|
|
|
|
port,
|
2023-11-06 20:06:33 +00:00
|
|
|
postflight,
|
2023-11-01 05:01:17 +00:00
|
|
|
});
|
2025-01-16 05:22:33 +00:00
|
|
|
} catch (error: any) {
|
2023-11-01 05:01:17 +00:00
|
|
|
console.log(
|
|
|
|
`${colors.FgRed}ERROR:${colors.Reset} CI process failed! => ${error.message}`
|
|
|
|
);
|
|
|
|
}
|
2023-10-29 07:35:26 +00:00
|
|
|
}
|
2023-11-01 05:01:17 +00:00
|
|
|
|
|
|
|
run();
|
|
|
|
|
|
|
|
process.on("exit", () => {
|
|
|
|
console.log("Process exiting ...");
|
|
|
|
});
|
|
|
|
|
|
|
|
process.on("beforeExit", () => {
|
|
|
|
console.log("Process Before exit ...");
|
|
|
|
});
|