67 lines
2.1 KiB
JavaScript
67 lines
2.1 KiB
JavaScript
import { execFileSync } from "node:child_process"
|
|
import { mkdir, readFile, writeFile, access } from "node:fs/promises"
|
|
import path from "node:path"
|
|
import extract from "extract-zip"
|
|
import { desktopRoot, electronVersion } from "./config.mjs"
|
|
|
|
if (!process.env.OTUNES_ELECTRON_SOURCE) {
|
|
throw new Error(
|
|
"Set OTUNES_ELECTRON_SOURCE to a synced Electron src directory. See apps/desktop/README.md."
|
|
)
|
|
}
|
|
const source = path.resolve(process.env.OTUNES_ELECTRON_SOURCE)
|
|
const tag = execFileSync(
|
|
"git",
|
|
["describe", "--tags", "--exact-match", "HEAD"],
|
|
{
|
|
cwd: path.join(source, "electron"),
|
|
encoding: "utf8",
|
|
}
|
|
).trim()
|
|
if (tag !== `v${electronVersion}`)
|
|
throw new Error(`Check out and sync Electron v${electronVersion} first`)
|
|
await access(path.join(source, "media", "media_options.gni"))
|
|
const arch = process.env.OTUNES_ELECTRON_ARCH ?? process.arch
|
|
if (!["x64", "arm64"].includes(arch))
|
|
throw new Error("Electron target must be x64 or arm64")
|
|
const outputName = `out/otunes-${arch}`
|
|
const output = path.join(source, outputName)
|
|
await mkdir(output, { recursive: true })
|
|
await writeFile(
|
|
path.join(output, "args.gn"),
|
|
`${await readFile(path.join(desktopRoot, "runtime.gn"), "utf8")}\ntarget_cpu = "${arch}"\n`
|
|
)
|
|
for (const [command, args] of [
|
|
["gn", ["gen", outputName, "--fail-on-unused-args"]],
|
|
["ninja", ["-C", outputName, "electron:electron_dist_zip"]],
|
|
]) {
|
|
execFileSync(command, args, {
|
|
cwd: source,
|
|
stdio: "inherit",
|
|
shell: process.platform === "win32",
|
|
})
|
|
}
|
|
// Use a fresh directory so stale files cannot enter a packaged runtime.
|
|
const distribution = path.join(
|
|
desktopRoot,
|
|
"runtime",
|
|
`${electronVersion}-${process.platform}-${arch}`
|
|
)
|
|
await mkdir(path.dirname(distribution), { recursive: true })
|
|
await mkdir(distribution)
|
|
await extract(path.join(output, "dist.zip"), { dir: distribution })
|
|
await writeFile(
|
|
path.join(distribution, "otunes-runtime.json"),
|
|
JSON.stringify(
|
|
{
|
|
version: electronVersion,
|
|
platform: process.platform,
|
|
arch,
|
|
enable_platform_ac3_eac3_audio: true,
|
|
},
|
|
null,
|
|
2
|
|
)
|
|
)
|
|
console.log(`Custom runtime ready. Set OTUNES_ELECTRON_DIST=${distribution}`)
|