farmcontrol-ui/scripts/run-electrobun-build.mjs
Tom Butcher 6690516be3
Some checks failed
farmcontrol/farmcontrol-ui/pipeline/head There was a failure building this commit
Update dependencies and enhance build scripts for Electrobun
- Updated `electrobun` dependency to version `1.18.4-beta.19` in `package.json` and `bun.lock`.
- Added `rcedit` and `@tweenjs/tween.js` dependencies to `bun.lock`.
- Modified `Jenkinsfile` to clean up additional staging directories for production builds.
- Refactored `electrobun.config.ts` to dynamically read the `package.json` path.
- Introduced new scripts for managing Hutch installation and execution, improving the build process.
- Enhanced artifact finalization logic to support multiple build environments and streamline platform directory resolution.
2026-08-07 21:35:16 +01:00

106 lines
2.6 KiB
JavaScript

import { spawnSync } from "node:child_process";
import path from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
import { getReleaseArch, isBundleCefEnabled } from "./release-artifact-utils.mjs";
import { resolveHutchCommand } from "./resolve-hutch-command.mjs";
const rootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
const buildEnv = process.env.ELECTROBUN_BUILD_ENV || "stable";
const targetArch = getReleaseArch(
process.env.ELECTROBUN_TARGET_ARCH ||
process.env.ELECTROBUN_FORCE_ARCH ||
process.arch,
);
const bundleCef = isBundleCefEnabled();
function runScript(scriptName) {
const result = spawnSync("bun", [path.join(rootDir, "scripts", scriptName)], {
cwd: rootDir,
stdio: "inherit",
env: process.env,
});
if (result.status !== 0) {
process.exit(result.status ?? 1);
}
}
runScript("ensure-hutch.mjs");
runScript("patch-electrobun-src.mjs");
const macosEffectsResult = spawnSync(
"bun",
[path.join(rootDir, "scripts/build-macos-effects.mjs")],
{ cwd: rootDir, stdio: "inherit", env: process.env },
);
if (macosEffectsResult.status !== 0) {
process.exit(macosEffectsResult.status ?? 1);
}
if (process.platform === "darwin") {
const { validateMacosEffectsDylib, outFile } = await import(
pathToFileURL(
path.join(rootDir, "scripts/build-macos-effects.mjs"),
).href
);
if (!validateMacosEffectsDylib({ dylibPath: outFile })) {
console.error(
"run-electrobun-build: macOS window effects dylib is missing or invalid.",
);
process.exit(1);
}
}
const ensureCoreEnv = {
...process.env,
ELECTROBUN_TARGET_ARCH: targetArch,
ELECTROBUN_FORCE_ARCH: targetArch,
};
const ensureCoreResult = spawnSync(
"bun",
[path.join(rootDir, "scripts/ensure-electrobun-core.mjs")],
{
cwd: rootDir,
stdio: "inherit",
env: ensureCoreEnv,
},
);
if (ensureCoreResult.status !== 0) {
process.exit(ensureCoreResult.status ?? 1);
}
const env = {
...process.env,
ELECTROBUN_BUILD_ENV: buildEnv,
ELECTROBUN_OS: "macos",
ELECTROBUN_ARCH: targetArch,
ELECTROBUN_FORCE_ARCH: targetArch,
ELECTROBUN_TARGET_ARCH: targetArch,
NODE_ENV: process.env.NODE_ENV || "production",
};
const hutchCommand = resolveHutchCommand(env);
console.log(
`run-electrobun-build: env=${buildEnv} os=macos arch=${targetArch} cef=${bundleCef} (host ${getReleaseArch(process.arch)})`,
);
const result = spawnSync(
hutchCommand,
["electrobun", "build", `--env=${buildEnv}`],
{
cwd: rootDir,
stdio: "inherit",
env,
},
);
if (result.status !== 0) {
process.exit(result.status ?? 1);
}