- Replaced the macOS build command in package.json to use a new script for better architecture handling. - Added a new script for building macOS applications that supports both arm64 and x64 architectures. - Enhanced the finalize-desktop-artifacts script to improve artifact discovery and cleanup, ensuring proper handling of macOS DMG and app bundles. - Updated functions to streamline the process of finding and publishing artifacts, improving overall reliability.
54 lines
1.4 KiB
JavaScript
54 lines
1.4 KiB
JavaScript
import { spawnSync } from "node:child_process";
|
|
import { fileURLToPath } from "node:url";
|
|
import path from "node:path";
|
|
|
|
const rootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
const hostArch = process.arch === "arm64" ? "arm64" : "x64";
|
|
const targetArchs = ["arm64", "x64"];
|
|
|
|
function run(command, args, options = {}) {
|
|
const result = spawnSync(command, args, {
|
|
cwd: rootDir,
|
|
stdio: "inherit",
|
|
env: process.env,
|
|
...options,
|
|
});
|
|
|
|
if (result.status !== 0) {
|
|
process.exit(result.status ?? 1);
|
|
}
|
|
}
|
|
|
|
function getElectrobunCommand(targetArch) {
|
|
const electrobunArgs = ["electrobun", "build", "--env=stable"];
|
|
|
|
if (targetArch === hostArch) {
|
|
return { command: "bun", args: electrobunArgs };
|
|
}
|
|
|
|
if (hostArch === "arm64" && targetArch === "x64") {
|
|
return { command: "arch", args: ["-x86_64", "bun", ...electrobunArgs] };
|
|
}
|
|
|
|
if (hostArch === "x64" && targetArch === "arm64") {
|
|
return { command: "arch", args: ["-arm64", "bun", ...electrobunArgs] };
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
run("bun", ["run", "build"]);
|
|
|
|
for (const targetArch of targetArchs) {
|
|
const invocation = getElectrobunCommand(targetArch);
|
|
if (!invocation) {
|
|
console.warn(
|
|
`Skipping macOS ${targetArch} build: unsupported cross-compile from ${hostArch}.`,
|
|
);
|
|
continue;
|
|
}
|
|
|
|
console.log(`\n=== Building macOS ${targetArch} ===\n`);
|
|
run(invocation.command, invocation.args);
|
|
}
|