electron-builder.config.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import { execFile } from "node:child_process"
  2. import path from "node:path"
  3. import { fileURLToPath } from "node:url"
  4. import { promisify } from "node:util"
  5. import type { Configuration } from "electron-builder"
  6. const execFileAsync = promisify(execFile)
  7. const rootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..")
  8. const signScript = path.join(rootDir, "script", "sign-windows.ps1")
  9. async function signWindows(configuration: { path: string }) {
  10. if (process.platform !== "win32") return
  11. if (process.env.GITHUB_ACTIONS !== "true") return
  12. await execFileAsync(
  13. "pwsh",
  14. ["-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", signScript, configuration.path],
  15. { cwd: rootDir },
  16. )
  17. }
  18. const channel = (() => {
  19. const raw = process.env.OPENCODE_CHANNEL
  20. if (raw === "dev" || raw === "beta" || raw === "prod") return raw
  21. return "dev"
  22. })()
  23. const getBase = (): Configuration => ({
  24. artifactName: "opencode-desktop-${os}-${arch}.${ext}",
  25. directories: {
  26. output: "dist",
  27. buildResources: "resources",
  28. },
  29. files: ["out/**/*", "resources/**/*"],
  30. extraResources: [
  31. {
  32. from: "native/",
  33. to: "native/",
  34. filter: ["index.js", "index.d.ts", "build/Release/mac_window.node", "swift-build/**"],
  35. },
  36. ],
  37. mac: {
  38. category: "public.app-category.developer-tools",
  39. icon: `resources/icons/icon.icns`,
  40. hardenedRuntime: true,
  41. gatekeeperAssess: false,
  42. entitlements: "resources/entitlements.plist",
  43. entitlementsInherit: "resources/entitlements.plist",
  44. notarize: true,
  45. target: ["dmg", "zip"],
  46. },
  47. dmg: {
  48. sign: true,
  49. },
  50. protocols: {
  51. name: "OpenCode",
  52. schemes: ["opencode"],
  53. },
  54. win: {
  55. icon: `resources/icons/icon.ico`,
  56. signtoolOptions: {
  57. sign: signWindows,
  58. },
  59. target: ["nsis"],
  60. verifyUpdateCodeSignature: false,
  61. },
  62. nsis: {
  63. oneClick: true,
  64. perMachine: false,
  65. installerIcon: `resources/icons/icon.ico`,
  66. installerHeaderIcon: `resources/icons/icon.ico`,
  67. },
  68. linux: {
  69. icon: `resources/icons`,
  70. category: "Development",
  71. target: ["AppImage", "deb", "rpm"],
  72. },
  73. })
  74. function getConfig() {
  75. const base = getBase()
  76. switch (channel) {
  77. case "dev": {
  78. return {
  79. ...base,
  80. appId: "ai.opencode.desktop.dev",
  81. productName: "OpenCode Dev",
  82. rpm: { packageName: "opencode-dev" },
  83. }
  84. }
  85. case "beta": {
  86. return {
  87. ...base,
  88. appId: "ai.opencode.desktop.beta",
  89. productName: "OpenCode Beta",
  90. protocols: { name: "OpenCode Beta", schemes: ["opencode"] },
  91. publish: { provider: "github", owner: "anomalyco", repo: "opencode-beta", channel: "latest" },
  92. rpm: { packageName: "opencode-beta" },
  93. }
  94. }
  95. case "prod": {
  96. return {
  97. ...base,
  98. appId: "ai.opencode.desktop",
  99. productName: "OpenCode",
  100. protocols: { name: "OpenCode", schemes: ["opencode"] },
  101. publish: { provider: "github", owner: "anomalyco", repo: "opencode", channel: "latest" },
  102. rpm: { packageName: "opencode" },
  103. }
  104. }
  105. }
  106. }
  107. export default getConfig()