diff --git a/extra/build-healthcheck.js b/extra/build-healthcheck.js index e4c8026ab..d771a719f 100644 --- a/extra/build-healthcheck.js +++ b/extra/build-healthcheck.js @@ -1,27 +1,62 @@ 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("No platform??"); + console.error("Error: No platform specified."); process.exit(1); } -if (platform === "linux/arm/v7") { - console.log("Arch: armv7"); - if (fs.existsSync("./extra/healthcheck-armv7")) { - fs.renameSync("./extra/healthcheck-armv7", "./extra/healthcheck"); - console.log("Already built in the host, skip."); - process.exit(0); - } else { - console.log("prebuilt not found, it will be slow! You should execute `npm run build-healthcheck-armv7` before build."); - } -} else { - if (fs.existsSync("./extra/healthcheck-armv7")) { - fs.rmSync("./extra/healthcheck-armv7"); +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); } } -const output = childProcess.execSync("go build -x -o ./extra/healthcheck ./extra/healthcheck.go").toString("utf8"); -console.log(output); +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();