|
2 | 2 | import { $ } from "bun" |
3 | 3 | import { cp, mkdir, readdir, rm } from "node:fs/promises" |
4 | 4 | import path from "node:path" |
| 5 | +import { getConfig } from "../electron-builder.config" |
5 | 6 | import { getCurrentCli, resolveChannel } from "./utils" |
6 | 7 |
|
7 | 8 | // Packages the built app (out/) for OPENCODE_TARGET into dist/desktop at the repository root, unsigned: |
@@ -50,12 +51,29 @@ if (!app && os === "mac") { |
50 | 51 | const bundles = (await readdir(parent)).filter((file) => file.endsWith(".app")) |
51 | 52 |
|
52 | 53 | if (bundles.length !== 1) throw new Error(`Expected one .app bundle in ${parent}, found ${bundles.join(", ")}`) |
| 54 | + await writeUpdateConfig(path.join(parent, bundles[0], "Contents", "Resources")) |
53 | 55 | await $`tar -cf ${path.join(out, `opencode-desktop-mac-${cli.cpu}.app.tar`)} -C ${parent} ${bundles[0]}` |
54 | 56 | } |
55 | 57 |
|
56 | 58 | if (!app && os === "win") { |
57 | 59 | await $`bunx electron-builder ${flags} --dir` |
58 | | - await cp(path.join("dist", cli.cpu === "arm64" ? "win-arm64-unpacked" : "win-unpacked"), path.join(out, "app"), { |
59 | | - recursive: true, |
60 | | - }) |
| 60 | + const unpacked = path.join("dist", cli.cpu === "arm64" ? "win-arm64-unpacked" : "win-unpacked") |
| 61 | + await writeUpdateConfig(path.join(unpacked, "resources")) |
| 62 | + await cp(unpacked, path.join(out, "app"), { recursive: true }) |
| 63 | +} |
| 64 | + |
| 65 | +// electron-builder writes resources/app-update.yml only for dmg, zip and nsis targets, not for --dir builds. |
| 66 | +// electron-updater reads its feed from that file, so write the one those targets would. |
| 67 | +async function writeUpdateConfig(resources: string) { |
| 68 | + const publish = getConfig().publish |
| 69 | + const name: string = (await Bun.file("package.json").json()).name |
| 70 | + await Bun.write( |
| 71 | + path.join(resources, "app-update.yml"), |
| 72 | + [ |
| 73 | + `provider: ${publish.provider}`, |
| 74 | + `url: ${publish.url}`, |
| 75 | + `channel: ${publish.channel}`, |
| 76 | + `updaterCacheDirName: '${name.replace(/[/\\:*?"<>|]/g, "").toLowerCase()}-updater'`, |
| 77 | + ].join("\n") + "\n", |
| 78 | + ) |
61 | 79 | } |