publish.ts 752 B

123456789101112131415161718192021222324
  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 import("./build")
  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-expect-error
  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`
  19. await $`npm publish *.tgz --tag ${Script.channel} --access public`
  20. await Bun.write("package.json", JSON.stringify(original, null, 2))