release.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env bun
  2. import { $ } from "bun"
  3. import pkg from "../package.json"
  4. const version = `0.0.0-${Date.now()}`
  5. const ARCH = {
  6. arm64: "arm64",
  7. x64: "amd64",
  8. }
  9. const OS = {
  10. linux: "linux",
  11. darwin: "mac",
  12. win32: "windows",
  13. }
  14. const targets = [
  15. ["linux", "arm64"],
  16. ["linux", "x64"],
  17. ["darwin", "x64"],
  18. ["darwin", "arm64"],
  19. ["windows", "x64"],
  20. ]
  21. await $`rm -rf dist`
  22. const optionalDependencies: Record<string, string> = {}
  23. for (const [os, arch] of targets) {
  24. console.log(`building ${os}-${arch}`)
  25. const name = `${pkg.name}-${os}-${arch}`
  26. await $`mkdir -p dist/${name}/bin`
  27. await $`bun build --compile --minify --target=bun-${os}-${arch} --outfile=dist/${name}/bin/${pkg.name} ./src/index.ts`
  28. await Bun.file(`dist/${name}/package.json`).write(
  29. JSON.stringify(
  30. {
  31. name,
  32. version,
  33. os: [os],
  34. cpu: [arch],
  35. },
  36. null,
  37. 2,
  38. ),
  39. )
  40. 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}.mjs`,
  51. },
  52. version,
  53. optionalDependencies,
  54. },
  55. null,
  56. 2,
  57. ),
  58. )
  59. await $`cd ./dist/${pkg.name} && npm publish --access public --tag latest`