2
0

publish.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132
  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. async function published(name: string, version: string) {
  8. return (await $`npm view ${name}@${version} version`.nothrow()).exitCode === 0
  9. }
  10. await $`bun tsc`
  11. const pkg = await import("../package.json").then(
  12. (m) => m.default as { name: string; version: string; exports: Record<string, string> },
  13. )
  14. const original = JSON.parse(JSON.stringify(pkg))
  15. if (await published(pkg.name, pkg.version)) {
  16. console.log(`already published ${pkg.name}@${pkg.version}`)
  17. process.exit(0)
  18. }
  19. for (const [key, value] of Object.entries(pkg.exports)) {
  20. const file = value.replace("./src/", "./dist/").replace(".ts", "")
  21. // @ts-ignore
  22. pkg.exports[key] = {
  23. import: file + ".js",
  24. types: file + ".d.ts",
  25. }
  26. }
  27. await Bun.write("package.json", JSON.stringify(pkg, null, 2))
  28. await $`bun pm pack && npm publish *.tgz --tag ${Script.channel} --access public`
  29. await Bun.write("package.json", JSON.stringify(original, null, 2))