publish.ts 819 B

1234567891011121314151617181920212223242526
  1. #!/usr/bin/env bun
  2. import { Script } from "@opencode-ai/script"
  3. import { $ } from "bun"
  4. import { rm } from "node:fs/promises"
  5. import { fileURLToPath } from "node:url"
  6. process.chdir(fileURLToPath(new URL("..", import.meta.url)))
  7. const pkg = (await Bun.file("package.json").json()) as { name: string; version: string }
  8. const tarball = `${pkg.name.replace("@", "").replace("/", "-")}-${pkg.version}.tgz`
  9. if ((await $`npm view ${pkg.name}@${pkg.version} version`.nothrow()).exitCode === 0) {
  10. console.log(`already published ${pkg.name}@${pkg.version}`)
  11. process.exit(0)
  12. }
  13. try {
  14. await $`bun run typecheck`
  15. await $`bun run test`
  16. await rm(tarball, { force: true })
  17. await $`bun pm pack`
  18. await $`npm publish ${tarball} --access public --tag ${Script.channel}`
  19. } finally {
  20. await rm(tarball, { force: true })
  21. }