package-beta.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env bun
  2. import { $ } from "bun"
  3. import { existsSync } from "node:fs"
  4. import { join, resolve } from "node:path"
  5. import { validateRuntimeBundle } from "./runtime-bundle"
  6. // Build and package locally. Publishing is always a separate, explicit action.
  7. process.env.OPENCODE_CHANNEL = "beta"
  8. const unsigned = process.argv.includes("--unsigned")
  9. if (unsigned) {
  10. process.env.CSC_IDENTITY_AUTO_DISCOVERY = "false"
  11. // An unsigned local preview must never offer an updater feed as a release.
  12. delete process.env.LAMBDA_SCIENTIST_UPDATE_URL
  13. }
  14. const external = process.argv.includes("--external-services")
  15. process.env.LAMBDA_AGENT_EXTERNAL_SERVICES = external ? "1" : "0"
  16. if (process.argv.includes("--mirror")) {
  17. process.env.ELECTRON_MIRROR ??= "https://npmmirror.com/mirrors/electron/"
  18. process.env.ELECTRON_BUILDER_BINARIES_MIRROR ??= "https://npmmirror.com/mirrors/electron-builder-binaries/"
  19. }
  20. if (!external && process.env.LAMBDA_AGENT_RUNTIME_DIR) await $`bun ./scripts/prepare-paas-runtime.ts`
  21. if (!external) {
  22. const file = Bun.file("resources/agentpaas-runtime/desktop-runtime.json")
  23. if (!(await file.exists()))
  24. throw new Error(
  25. "完整版缺少本地运行组件。先准备 LAMBDA_AGENT_RUNTIME_DIR;仅连接已有服务的精简版请显式使用 --external-services。",
  26. )
  27. await validateRuntimeBundle("resources/agentpaas-runtime")
  28. }
  29. if (process.platform === "win32") {
  30. if (process.arch !== "x64") throw new Error("Build the Windows Beta installer using x64 Bun")
  31. const runtime = process.env.LAMBDA_AGENT_WINDOWS_RUNTIME
  32. if (!runtime) throw new Error("Set LAMBDA_AGENT_WINDOWS_RUNTIME to the prepared Windows runtime directory")
  33. process.env.LAMBDA_AGENT_WINDOWS_RUNTIME = resolve(runtime)
  34. for (const file of ["git/cmd/git.exe", "git/LICENSE.txt", "ripgrep/rg.exe", "ripgrep/COPYING"]) {
  35. if (!existsSync(join(runtime, file))) throw new Error(`Missing Windows runtime file: ${file}`)
  36. }
  37. }
  38. await $`bun run build`
  39. const electronDist = process.platform === "win32" && process.env.LAMBDA_AGENT_ELECTRON_DIST
  40. const options = [
  41. ...(electronDist ? [`--config.electronDist=${resolve(electronDist)}`] : []),
  42. ...(process.platform === "win32" ? ["--win", "nsis", "--x64"] : []),
  43. ...(process.argv.includes("--dir") ? ["--dir"] : []),
  44. ...(unsigned && process.platform === "darwin" ? ["-c.mac.notarize=false", "-c.dmg.sign=false"] : []),
  45. ]
  46. await $`bun x --no-install electron-builder --config electron-builder.config.ts --publish never ${options}`