publish.ts 1.0 KB

123456789101112131415161718192021222324252627282930
  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. const pkg = (await import("../package.json").then((m) => m.default)) as {
  7. exports: Record<string, string | object>
  8. }
  9. const original = JSON.parse(JSON.stringify(pkg))
  10. function transformExports(exports: Record<string, string | object>) {
  11. for (const [key, value] of Object.entries(exports)) {
  12. if (typeof value === "object" && value !== null) {
  13. transformExports(value as Record<string, string | object>)
  14. } else if (typeof value === "string") {
  15. const file = value.replace("./src/", "./dist/").replace(".ts", "")
  16. exports[key] = {
  17. import: file + ".js",
  18. types: file + ".d.ts",
  19. }
  20. }
  21. }
  22. }
  23. transformExports(pkg.exports)
  24. await Bun.write("package.json", JSON.stringify(pkg, null, 2))
  25. await $`bun pm pack`
  26. await $`npm publish *.tgz --tag ${Script.channel} --access public`
  27. await Bun.write("package.json", JSON.stringify(original, null, 2))