Kuma/extra/build-healthcheck.js
Tushar Kumar 1067908154
Update build-healthcheck.js
This script is designed to manage the platform-specific build process for a health check tool, particularly for Linux on the armv7 architecture. It handles renaming pre-built healthcheck files, removing outdated versions, and performing a Go-based build when necessary.
2024-10-24 21:35:26 +05:30

62 lines
1.8 KiB
JavaScript

const childProcess = require("child_process");
const fs = require("fs");
const path = require("path");
const platform = process.argv[2];
const healthcheckPath = "./extra/healthcheck";
const healthcheckArmPath = "./extra/healthcheck-armv7";
const healthcheckGoFile = "./extra/healthcheck.go";
if (!platform) {
console.error("Error: No platform specified.");
process.exit(1);
}
function renamePrebuiltHealthcheck() {
try {
fs.renameSync(healthcheckArmPath, healthcheckPath);
console.log("Prebuilt healthcheck for armv7 renamed successfully.");
} catch (error) {
console.error("Error renaming prebuilt healthcheck:", error.message);
process.exit(1);
}
}
function removeArmHealthcheck() {
if (fs.existsSync(healthcheckArmPath)) {
try {
fs.rmSync(healthcheckArmPath);
console.log("Old armv7 healthcheck removed.");
} catch (error) {
console.error("Error removing armv7 healthcheck:", error.message);
}
}
}
function buildHealthcheck() {
try {
const output = childProcess.execSync(`go build -x -o ${healthcheckPath} ${healthcheckGoFile}`).toString("utf8");
console.log("Build output:\n", output);
} catch (error) {
console.error("Error during build process:", error.message);
process.exit(1);
}
}
if (platform === "linux/arm/v7") {
console.log("Architecture: armv7");
if (fs.existsSync(healthcheckArmPath)) {
renamePrebuiltHealthcheck();
console.log("Already built in the host, skipping build.");
process.exit(0);
} else {
console.log("Prebuilt healthcheck not found. The build might be slow.");
console.log("Recommendation: Run `npm run build-healthcheck-armv7` before building.");
}
} else {
removeArmHealthcheck();
}
// Build the healthcheck
buildHealthcheck();