Files
otunes/apps/desktop/scripts/package.mjs
T
joshuafhigginsandClaude Opus 5.5 Verified f8e5dc7325 feat(desktop): ship the web UI as a static export
The static export now works away from the oTunes server. It picks a
server at /server (saved in localStorage), connects Convex to it, and
loads covers, avatars and streams from it. Streams and avatars pass the
session token as a `token` query parameter, which the song and avatar
routes accept alongside the cookie. The server allows any origin on /api.

Electron serves that export from 127.0.0.1:47836 and drops the bundled
Next.js server, the media gateway, symlink materializing and Sharp
pruning. The same export can ship in a Tauri app.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 00:15:35 -05:00

78 lines
2.8 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 })
await copyFile(
path.join(desktopRoot, "main.cjs"),
path.join(staging, "main.cjs")
)
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", "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",
})
}