publish.ts 730 B

123456789101112131415161718192021
  1. #!/usr/bin/env bun
  2. import { Script } from "@opencode-ai/script"
  3. import { $ } from "bun"
  4. const dir = new URL("..", import.meta.url).pathname
  5. process.chdir(dir)
  6. await $`bun tsc`
  7. const pkg = await import("../package.json").then((m) => m.default)
  8. const original = JSON.parse(JSON.stringify(pkg))
  9. for (const [key, value] of Object.entries(pkg.exports)) {
  10. const file = value.replace("./src/", "./dist/").replace(".ts", "")
  11. // @ts-ignore
  12. pkg.exports[key] = {
  13. import: file + ".js",
  14. types: file + ".d.ts",
  15. }
  16. }
  17. await Bun.write("package.json", JSON.stringify(pkg, null, 2))
  18. await $`bun pm pack && npm publish *.tgz --tag ${Script.channel} --access public`
  19. await Bun.write("package.json", JSON.stringify(original, null, 2))