build.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env bun
  2. import { fileURLToPath } from "url"
  3. const dir = fileURLToPath(new URL("..", import.meta.url))
  4. process.chdir(dir)
  5. import { $ } from "bun"
  6. import path from "path"
  7. import { createClient } from "@hey-api/openapi-ts"
  8. const openapiSource = process.env.OPENCODE_SDK_OPENAPI === "httpapi" ? "httpapi" : "hono"
  9. const opencode = path.resolve(dir, "../../opencode")
  10. if (openapiSource === "httpapi") {
  11. await $`bun dev generate --httpapi > ${dir}/openapi.json`.cwd(opencode)
  12. } else {
  13. await $`bun dev generate > ${dir}/openapi.json`.cwd(opencode)
  14. }
  15. await createClient({
  16. input: "./openapi.json",
  17. output: {
  18. path: "./src/v2/gen",
  19. tsConfigPath: path.join(dir, "tsconfig.json"),
  20. clean: true,
  21. },
  22. plugins: [
  23. {
  24. name: "@hey-api/typescript",
  25. exportFromIndex: false,
  26. },
  27. {
  28. name: "@hey-api/sdk",
  29. instance: "OpencodeClient",
  30. exportFromIndex: false,
  31. auth: false,
  32. paramsStructure: "flat",
  33. },
  34. {
  35. name: "@hey-api/client-fetch",
  36. exportFromIndex: false,
  37. baseUrl: "http://localhost:4096",
  38. },
  39. ],
  40. })
  41. await $`bun prettier --write src/gen`
  42. await $`bun prettier --write src/v2`
  43. await $`rm -rf dist`
  44. await $`bun tsc`
  45. await $`rm openapi.json`