2
0

electron-builder.config.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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: "resources/",
  33. to: "",
  34. filter: ["opencode-cli*"],
  35. },
  36. {
  37. from: "native/",
  38. to: "native/",
  39. filter: ["index.js", "index.d.ts", "build/Release/mac_window.node", "swift-build/**"],
  40. },
  41. ],
  42. mac: {
  43. category: "public.app-category.developer-tools",
  44. icon: `resources/icons/icon.icns`,
  45. hardenedRuntime: true,
  46. gatekeeperAssess: false,
  47. entitlements: "resources/entitlements.plist",
  48. entitlementsInherit: "resources/entitlements.plist",
  49. notarize: true,
  50. target: ["dmg", "zip"],
  51. },
  52. dmg: {
  53. sign: true,
  54. },
  55. protocols: {
  56. name: "OpenCode",
  57. schemes: ["opencode"],
  58. },
  59. win: {
  60. icon: `resources/icons/icon.ico`,
  61. signtoolOptions: {
  62. sign: signWindows,
  63. },
  64. target: ["nsis"],
  65. },
  66. nsis: {
  67. oneClick: false,
  68. allowToChangeInstallationDirectory: true,
  69. installerIcon: `resources/icons/icon.ico`,
  70. installerHeaderIcon: `resources/icons/icon.ico`,
  71. },
  72. linux: {
  73. icon: `resources/icons`,
  74. category: "Development",
  75. target: ["AppImage", "deb", "rpm"],
  76. },
  77. })
  78. function getConfig() {
  79. const base = getBase()
  80. switch (channel) {
  81. case "dev": {
  82. return {
  83. ...base,
  84. appId: "ai.opencode.desktop.dev",
  85. productName: "OpenCode Dev",
  86. rpm: { packageName: "opencode-dev" },
  87. }
  88. }
  89. case "beta": {
  90. return {
  91. ...base,
  92. appId: "ai.opencode.desktop.beta",
  93. productName: "OpenCode Beta",
  94. protocols: { name: "OpenCode Beta", schemes: ["opencode"] },
  95. publish: { provider: "github", owner: "anomalyco", repo: "opencode-beta", channel: "latest" },
  96. rpm: { packageName: "opencode-beta" },
  97. }
  98. }
  99. case "prod": {
  100. return {
  101. ...base,
  102. appId: "ai.opencode.desktop",
  103. productName: "OpenCode",
  104. protocols: { name: "OpenCode", schemes: ["opencode"] },
  105. publish: { provider: "github", owner: "anomalyco", repo: "opencode", channel: "latest" },
  106. rpm: { packageName: "opencode" },
  107. }
  108. }
  109. }
  110. }
  111. export default getConfig()