| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- #!/usr/bin/env bun
- import { $ } from "bun"
- import { existsSync } from "node:fs"
- import { join, resolve } from "node:path"
- import { validateRuntimeBundle } from "./runtime-bundle"
- // Build and package locally. Publishing is always a separate, explicit action.
- process.env.OPENCODE_CHANNEL = "beta"
- const unsigned = process.argv.includes("--unsigned")
- if (unsigned) {
- process.env.CSC_IDENTITY_AUTO_DISCOVERY = "false"
- // An unsigned local preview must never offer an updater feed as a release.
- delete process.env.LAMBDA_SCIENTIST_UPDATE_URL
- }
- const external = process.argv.includes("--external-services")
- process.env.LAMBDA_AGENT_EXTERNAL_SERVICES = external ? "1" : "0"
- if (process.argv.includes("--mirror")) {
- process.env.ELECTRON_MIRROR ??= "https://npmmirror.com/mirrors/electron/"
- process.env.ELECTRON_BUILDER_BINARIES_MIRROR ??= "https://npmmirror.com/mirrors/electron-builder-binaries/"
- }
- if (!external && process.env.LAMBDA_AGENT_RUNTIME_DIR) await $`bun ./scripts/prepare-paas-runtime.ts`
- if (!external) {
- const file = Bun.file("resources/agentpaas-runtime/desktop-runtime.json")
- if (!(await file.exists()))
- throw new Error(
- "完整版缺少本地运行组件。先准备 LAMBDA_AGENT_RUNTIME_DIR;仅连接已有服务的精简版请显式使用 --external-services。",
- )
- await validateRuntimeBundle("resources/agentpaas-runtime")
- }
- if (process.platform === "win32") {
- if (process.arch !== "x64") throw new Error("Build the Windows Beta installer using x64 Bun")
- const runtime = process.env.LAMBDA_AGENT_WINDOWS_RUNTIME
- if (!runtime) throw new Error("Set LAMBDA_AGENT_WINDOWS_RUNTIME to the prepared Windows runtime directory")
- process.env.LAMBDA_AGENT_WINDOWS_RUNTIME = resolve(runtime)
- for (const file of ["git/cmd/git.exe", "git/LICENSE.txt", "ripgrep/rg.exe", "ripgrep/COPYING"]) {
- if (!existsSync(join(runtime, file))) throw new Error(`Missing Windows runtime file: ${file}`)
- }
- }
- await $`bun run build`
- const electronDist = process.platform === "win32" && process.env.LAMBDA_AGENT_ELECTRON_DIST
- const options = [
- ...(electronDist ? [`--config.electronDist=${resolve(electronDist)}`] : []),
- ...(process.platform === "win32" ? ["--win", "nsis", "--x64"] : []),
- ...(process.argv.includes("--dir") ? ["--dir"] : []),
- ...(unsigned && process.platform === "darwin" ? ["-c.mac.notarize=false", "-c.dmg.sign=false"] : []),
- ]
- await $`bun x --no-install electron-builder --config electron-builder.config.ts --publish never ${options}`
|