publish.ts 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env bun
  2. import { Script } from "@opencode-ai/script"
  3. import { $ } from "bun"
  4. import { fileURLToPath } from "url"
  5. const dir = fileURLToPath(new URL("..", import.meta.url))
  6. process.chdir(dir)
  7. const pkg = (await import("../package.json").then((m) => m.default)) as {
  8. exports: Record<string, string | object>
  9. }
  10. const original = JSON.parse(JSON.stringify(pkg))
  11. function transformExports(exports: Record<string, string | object>) {
  12. for (const [key, value] of Object.entries(exports)) {
  13. if (typeof value === "object" && value !== null) {
  14. transformExports(value as Record<string, string | object>)
  15. } else if (typeof value === "string") {
  16. const file = value.replace("./src/", "./dist/").replace(".ts", "")
  17. exports[key] = {
  18. import: file + ".js",
  19. types: file + ".d.ts",
  20. }
  21. }
  22. }
  23. }
  24. transformExports(pkg.exports)
  25. await Bun.write("package.json", JSON.stringify(pkg, null, 2))
  26. await $`bun pm pack`
  27. await $`npm publish *.tgz --tag ${Script.channel} --access public`
  28. await Bun.write("package.json", JSON.stringify(original, null, 2))