2
0

publish.ts 782 B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/env bun
  2. const dir = new URL("..", import.meta.url).pathname
  3. process.chdir(dir)
  4. import { $ } from "bun"
  5. await $`bun tsc`
  6. const pkg = await import("../package.json").then((m) => m.default)
  7. const original = JSON.parse(JSON.stringify(pkg))
  8. for (const [key, value] of Object.entries(pkg.exports)) {
  9. const file = value.replace("./src/", "./dist/").replace(".ts", "")
  10. pkg.exports[key] = {
  11. import: file + ".js",
  12. types: file + ".d.ts",
  13. }
  14. }
  15. await Bun.write("package.json", JSON.stringify(pkg, null, 2))
  16. const snapshot = process.env["OPENCODE_SNAPSHOT"] === "true"
  17. if (snapshot) {
  18. await $`bun publish --tag snapshot --access public`
  19. }
  20. if (!snapshot) {
  21. await $`bun publish --access public`
  22. }
  23. await Bun.write("package.json", JSON.stringify(original, null, 2))