farmcontrol-ui/scripts/resolve-hutch-command.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

36 lines
1.2 KiB
JavaScript

import { existsSync, readFileSync } from "node:fs";
import { homedir, platform } from "node:os";
import path from "node:path";
import { fileURLToPath } from "node:url";
const rootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
function hutchChannelForElectrobunVersion(version) {
return version.includes("-") ? "canary" : "production";
}
function hutchBinaryName(channel) {
const base = channel === "canary" ? "hutch-canary" : "hutch";
return platform() === "win32" ? `${base}.exe` : base;
}
export function getElectrobunVersion() {
const packageJsonPath = path.join(rootDir, "node_modules/electrobun/package.json");
return JSON.parse(readFileSync(packageJsonPath, "utf8")).version;
}
export function resolveHutchCommand(environment = process.env) {
if (environment.ELECTROBUN_HUTCH_BINARY) {
return environment.ELECTROBUN_HUTCH_BINARY;
}
const channel = hutchChannelForElectrobunVersion(getElectrobunVersion());
const dashHome = environment.DASH_HOME || path.join(homedir(), ".dash");
const pathApi = platform() === "win32" ? path.win32 : path.posix;
return pathApi.join(dashHome, "bin", hutchBinaryName(channel));
}
export function hutchIsInstalled(command = resolveHutchCommand()) {
return existsSync(command);
}