release.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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-${new Date().toISOString().slice(0, 16).replace(/[-:T]/g, "")}`
  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 main.Version=${version}" -o ../opencode/dist/${name}/bin/tui ../tui/cmd/opencode/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 $`cp ./script/postinstall.js ./dist/${pkg.name}/postinstall.js`
  46. await Bun.file(`./dist/${pkg.name}/package.json`).write(
  47. JSON.stringify(
  48. {
  49. name: pkg.name + "-ai",
  50. bin: {
  51. [pkg.name]: `./bin/${pkg.name}`,
  52. },
  53. scripts: {
  54. postinstall: "node ./postinstall.js",
  55. },
  56. version,
  57. optionalDependencies,
  58. },
  59. null,
  60. 2,
  61. ),
  62. )
  63. if (!dry)
  64. await $`cd ./dist/${pkg.name} && npm publish --access public --tag latest`