| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- import { execFile } from "node:child_process"
- import path from "node:path"
- import { fileURLToPath } from "node:url"
- import { promisify } from "node:util"
- import type { Configuration } from "electron-builder"
- const execFileAsync = promisify(execFile)
- const packageDir = path.dirname(fileURLToPath(import.meta.url))
- const rootDir = path.resolve(packageDir, "../..")
- const signScript = path.join(rootDir, "script", "sign-windows.ps1")
- const metainfoFpm = (appId: string) =>
- `${path.join(packageDir, "resources", `${appId}.metainfo.xml`)}=/usr/share/metainfo/${appId}.metainfo.xml`
- async function signWindows(configuration: { path: string }) {
- if (process.platform !== "win32") return
- if (process.env.GITHUB_ACTIONS !== "true") return
- await execFileAsync(
- "pwsh",
- ["-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", signScript, configuration.path],
- { cwd: rootDir },
- )
- }
- const channel = (() => {
- const raw = process.env.OPENCODE_CHANNEL
- if (raw === "dev" || raw === "beta" || raw === "prod") return raw
- return "dev"
- })()
- const APP_IDS = {
- dev: "org.lambda-scientist.desktop.dev",
- beta: "org.lambda-scientist.desktop.beta",
- prod: "org.lambda-scientist.desktop",
- } as const
- const getBase = (appId: string): Configuration => ({
- artifactName: "lambda-scientist-${version}-${os}-${arch}.${ext}",
- directories: {
- output: "dist",
- buildResources: "resources",
- },
- // Linux launchers are .desktop files, so this is the desktop file name,
- // not just the app id. For prod, app id "org.lambda-scientist.desktop" becomes
- // "org.lambda-scientist.desktop.desktop".
- // https://developer.gnome.org/documentation/guidelines/maintainer/integrating.html
- // https://www.electron.build/docs/linux/
- extraMetadata: {
- desktopName: `${appId}.desktop`,
- },
- files: ["out/**/*", "resources/**/*", "!resources/opencode-cli*"],
- extraResources: [
- ...(channel === "dev"
- ? [
- {
- from: "resources/",
- to: "",
- filter: ["opencode-cli*"],
- },
- ]
- : []),
- ],
- mac: {
- category: "public.app-category.developer-tools",
- icon: `resources/icons/icon.icns`,
- hardenedRuntime: true,
- gatekeeperAssess: false,
- entitlements: "resources/entitlements.plist",
- entitlementsInherit: "resources/entitlements.plist",
- notarize: true,
- target: ["dmg", "zip"],
- },
- dmg: {
- sign: true,
- },
- protocols: {
- name: "λ-Scientist",
- schemes: ["lambda-scientist"],
- },
- win: {
- icon: `resources/icons/icon.ico`,
- signtoolOptions: {
- sign: signWindows,
- },
- target: ["nsis"],
- verifyUpdateCodeSignature: true,
- },
- nsis: {
- oneClick: true,
- perMachine: false,
- installerIcon: `resources/icons/icon.ico`,
- installerHeaderIcon: `resources/icons/icon.ico`,
- },
- linux: {
- icon: `resources/icons`,
- category: "Development",
- executableName: appId,
- desktop: {
- entry: {
- // Match the installed .desktop file and hicolor icon basename so
- // Linux shells can associate the running Electron window with its launcher.
- StartupWMClass: appId,
- },
- },
- target: ["AppImage", "deb", "rpm"],
- },
- })
- function updateSource(): Configuration["publish"] {
- const url = process.env.LAMBDA_SCIENTIST_UPDATE_URL
- if (!url) return null
- if (new URL(url).protocol !== "https:") throw new Error("Update URL must use HTTPS")
- return { provider: "generic", url, channel: channel === "beta" ? "beta" : "latest" }
- }
- function getConfig() {
- const appId = APP_IDS[channel]
- const base = getBase(appId)
- switch (channel) {
- case "dev": {
- return {
- ...base,
- appId,
- productName: "λ-Scientist Dev",
- deb: { fpm: [metainfoFpm(appId)] },
- rpm: { packageName: "lambda-scientist-dev", fpm: [metainfoFpm(appId)] },
- }
- }
- case "beta": {
- return {
- ...base,
- appId,
- productName: "λ-Scientist Beta",
- protocols: { name: "λ-Scientist Beta", schemes: ["lambda-scientist"] },
- publish: updateSource(),
- deb: { fpm: [metainfoFpm(appId)] },
- rpm: { packageName: "lambda-scientist-beta", fpm: [metainfoFpm(appId)] },
- }
- }
- case "prod": {
- return {
- ...base,
- appId,
- productName: "λ-Scientist",
- protocols: { name: "λ-Scientist", schemes: ["lambda-scientist"] },
- publish: updateSource(),
- deb: { fpm: [metainfoFpm(appId)] },
- rpm: { packageName: "lambda-scientist", fpm: [metainfoFpm(appId)] },
- }
- }
- }
- }
- export default getConfig()
|