release.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/env bun
  2. import { $ } from "bun"
  3. import pkg from "../package.json"
  4. const dry = process.argv.includes("--dry")
  5. const version = `0.0.0-${Date.now()}`
  6. const GOARCH: Record<string, string> = {
  7. arm64: "arm64",
  8. x64: "amd64",
  9. }
  10. const targets = [
  11. ["linux", "arm64"],
  12. ["linux", "x64"],
  13. ["darwin", "x64"],
  14. ["darwin", "arm64"],
  15. ["windows", "x64"],
  16. ]
  17. await $`rm -rf dist`
  18. const optionalDependencies: Record<string, string> = {}
  19. for (const [os, arch] of targets) {
  20. console.log(`building ${os}-${arch}`)
  21. const name = `${pkg.name}-${os}-${arch}`
  22. await $`mkdir -p dist/${name}/bin`
  23. await $`GOOS=${os} GOARCH=${GOARCH[arch]} go build -ldflags="-s -w -X github.com/sst/opencode/internal/version.Version=${version}" -o ../opencode/dist/${name}/bin/tui ../tui/main.go`.cwd(
  24. "../tui",
  25. )
  26. await $`bun build --define OPENCODE_VERSION="'${version}'" --compile --minify --target=bun-${os}-${arch} --outfile=dist/${name}/bin/opencode ./src/index.ts ./dist/${name}/bin/tui`
  27. await $`rm -rf ./dist/${name}/bin/tui`
  28. await Bun.file(`dist/${name}/package.json`).write(
  29. JSON.stringify(
  30. {
  31. name,
  32. version,
  33. os: [os === "windows" ? "win32" : os],
  34. cpu: [arch],
  35. },
  36. null,
  37. 2,
  38. ),
  39. )
  40. if (!dry) await $`cd dist/${name} && npm publish --access public --tag latest`
  41. optionalDependencies[name] = version
  42. }
  43. await $`mkdir -p ./dist/${pkg.name}`
  44. await $`cp -r ./bin ./dist/${pkg.name}/bin`
  45. await Bun.file(`./dist/${pkg.name}/package.json`).write(
  46. JSON.stringify(
  47. {
  48. name: pkg.name + "-ai",
  49. bin: {
  50. [pkg.name]: `./bin/${pkg.name}`,
  51. },
  52. version,
  53. optionalDependencies,
  54. },
  55. null,
  56. 2,
  57. ),
  58. )
  59. if (!dry)
  60. await $`cd ./dist/${pkg.name} && npm publish --access public --tag latest`