Drop the custom EAC-3 Chromium build and macOS packaging. Windows NSIS installers and Flatpaks for x64 and ARM64 now build in one Linux container image. Packaged installers previously lost the bundled Next.js dependencies: electron-builder drops the pnpm store and NSIS cannot carry symlinks. The bundle now replaces pnpm links with nested real copies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
76 lines
2.9 KiB
JavaScript
76 lines
2.9 KiB
JavaScript
import { build, Platform, Arch } from "electron-builder"
|
|
import { mkdir, copyFile, writeFile, rm, readFile } from "node:fs/promises"
|
|
import { createRequire } from "node:module"
|
|
import path from "node:path"
|
|
import { fileURLToPath } from "node:url"
|
|
|
|
// Packages stock Electron with the bundled UI from build-web.mjs.
|
|
// Usage: node scripts/package.mjs [windows|linux] [x64|arm64]
|
|
// Defaults to the host OS and both architectures. Linux hosts can build both
|
|
// targets: Windows needs Wine, ARM64 Flatpaks need qemu-user binfmt.
|
|
const desktopRoot = fileURLToPath(new URL("../", import.meta.url))
|
|
const hostTarget = { win32: "windows", linux: "linux" }[process.platform]
|
|
const [target = hostTarget, onlyArch] = process.argv.slice(2)
|
|
const platform = { windows: Platform.WINDOWS, linux: Platform.LINUX }[target]
|
|
if (!platform) throw new Error("Targets are windows or linux")
|
|
const architectures = onlyArch ? [onlyArch] : ["x64", "arm64"]
|
|
if (!architectures.every((arch) => arch === "x64" || arch === "arm64"))
|
|
throw new Error("Architectures are x64 or arm64")
|
|
|
|
const staging = path.join(desktopRoot, ".package")
|
|
await rm(staging, { recursive: true, force: true })
|
|
await mkdir(staging, { recursive: true })
|
|
for (const file of ["main.cjs", "server-config.cjs"])
|
|
await copyFile(path.join(desktopRoot, file), path.join(staging, file))
|
|
const pkg = JSON.parse(
|
|
await readFile(path.join(desktopRoot, "package.json"), "utf8")
|
|
)
|
|
const ref = process.env.OTUNES_DESKTOP_REF ?? ""
|
|
if (ref.startsWith("refs/tags/"))
|
|
pkg.version = ref.slice("refs/tags/".length).replace(/^v/, "")
|
|
delete pkg.devDependencies
|
|
delete pkg.scripts
|
|
await writeFile(
|
|
path.join(staging, "package.json"),
|
|
JSON.stringify(pkg, null, 2)
|
|
)
|
|
|
|
const { version: electronVersion } = createRequire(import.meta.url)(
|
|
"electron/package.json"
|
|
)
|
|
// One build per architecture: a multi-arch NSIS build merges both into one installer.
|
|
for (const arch of architectures) {
|
|
await build({
|
|
targets: platform.createTarget(undefined, Arch[arch]),
|
|
config: {
|
|
appId: "com.otunes.desktop",
|
|
productName: "oTunes",
|
|
electronVersion,
|
|
artifactName: "oTunes-${version}-${os}-${arch}.${ext}",
|
|
icon: path.resolve(desktopRoot, "../web/public/logo.png"),
|
|
directories: { app: staging, output: path.join(desktopRoot, "dist") },
|
|
files: ["main.cjs", "server-config.cjs", "package.json"],
|
|
extraResources: [
|
|
{ from: path.join(desktopRoot, "web"), to: "web", filter: ["**/*"] },
|
|
],
|
|
npmRebuild: false,
|
|
win: { target: ["nsis"] },
|
|
linux: { category: "AudioVideo", target: ["flatpak"] },
|
|
flatpak: {
|
|
runtimeVersion: "25.08",
|
|
baseVersion: "25.08",
|
|
finishArgs: [
|
|
"--socket=wayland",
|
|
"--socket=fallback-x11",
|
|
"--share=ipc",
|
|
"--device=dri",
|
|
"--socket=pulseaudio",
|
|
"--share=network",
|
|
],
|
|
},
|
|
publish: null,
|
|
},
|
|
publish: "never",
|
|
})
|
|
}
|