build.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 === "hono" ? "hono" : "httpapi"
  9. const opencode = path.resolve(dir, "../../opencode")
  10. // `bun dev generate` now derives the spec from the Effect HttpApi contract by
  11. // default; pass `--hono` to fall back to the legacy Hono spec for parity diffs.
  12. if (openapiSource === "httpapi") {
  13. await $`bun dev generate > ${dir}/openapi.json`.cwd(opencode)
  14. } else {
  15. await $`bun dev generate --hono > ${dir}/openapi.json`.cwd(opencode)
  16. }
  17. await createClient({
  18. input: "./openapi.json",
  19. output: {
  20. path: "./src/v2/gen",
  21. tsConfigPath: path.join(dir, "tsconfig.json"),
  22. clean: true,
  23. },
  24. plugins: [
  25. {
  26. name: "@hey-api/typescript",
  27. exportFromIndex: false,
  28. },
  29. {
  30. name: "@hey-api/sdk",
  31. instance: "OpencodeClient",
  32. exportFromIndex: false,
  33. auth: false,
  34. paramsStructure: "flat",
  35. },
  36. {
  37. name: "@hey-api/client-fetch",
  38. exportFromIndex: false,
  39. baseUrl: "http://localhost:4096",
  40. },
  41. ],
  42. })
  43. await $`bun prettier --write src/gen`
  44. await $`bun prettier --write src/v2`
  45. await $`rm -rf dist`
  46. await $`bun tsc`
  47. await $`rm openapi.json`