electron-builder.config.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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-electron-${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. },
  61. nsis: {
  62. oneClick: false,
  63. allowToChangeInstallationDirectory: true,
  64. installerIcon: `resources/icons/icon.ico`,
  65. installerHeaderIcon: `resources/icons/icon.ico`,
  66. },
  67. linux: {
  68. icon: `resources/icons`,
  69. category: "Development",
  70. target: ["AppImage", "deb", "rpm"],
  71. },
  72. })
  73. function getConfig() {
  74. const base = getBase()
  75. switch (channel) {
  76. case "dev": {
  77. return {
  78. ...base,
  79. appId: "ai.opencode.desktop.dev",
  80. productName: "OpenCode Dev",
  81. rpm: { packageName: "opencode-dev" },
  82. }
  83. }
  84. case "beta": {
  85. return {
  86. ...base,
  87. appId: "ai.opencode.desktop.beta",
  88. productName: "OpenCode Beta",
  89. protocols: { name: "OpenCode Beta", schemes: ["opencode"] },
  90. publish: { provider: "github", owner: "anomalyco", repo: "opencode-beta", channel: "latest" },
  91. rpm: { packageName: "opencode-beta" },
  92. }
  93. }
  94. case "prod": {
  95. return {
  96. ...base,
  97. appId: "ai.opencode.desktop",
  98. productName: "OpenCode",
  99. protocols: { name: "OpenCode", schemes: ["opencode"] },
  100. publish: { provider: "github", owner: "anomalyco", repo: "opencode", channel: "latest" },
  101. rpm: { packageName: "opencode" },
  102. }
  103. }
  104. }
  105. }
  106. export default getConfig()