generate.ts 940 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env bun
  2. const dir = new URL("..", import.meta.url).pathname
  3. process.chdir(dir)
  4. import { $ } from "bun"
  5. import fs from "fs/promises"
  6. import path from "path"
  7. console.log("=== Generating JS SDK ===")
  8. console.log()
  9. import { createClient } from "@hey-api/openapi-ts"
  10. await fs.rm(path.join(dir, "src/gen"), { recursive: true, force: true })
  11. await $`bun run ./src/index.ts generate > openapi.json`.cwd(path.resolve(dir, "../../opencode"))
  12. await createClient({
  13. input: "./openapi.json",
  14. output: "./src/gen",
  15. plugins: [
  16. {
  17. name: "@hey-api/typescript",
  18. exportFromIndex: false,
  19. },
  20. {
  21. name: "@hey-api/sdk",
  22. instance: "OpencodeClient",
  23. exportFromIndex: false,
  24. auth: false,
  25. },
  26. {
  27. name: "@hey-api/client-fetch",
  28. exportFromIndex: false,
  29. baseUrl: "http://localhost:4096",
  30. },
  31. ],
  32. })
  33. await $`bun prettier --write src/gen`
  34. await $`rm -rf dist`
  35. await $`bun tsc`