build.ts 997 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. await $`bun dev generate > ${dir}/openapi.json`.cwd(path.resolve(dir, "../../opencode"))
  9. await createClient({
  10. input: "./openapi.json",
  11. output: {
  12. path: "./src/v2/gen",
  13. tsConfigPath: path.join(dir, "tsconfig.json"),
  14. clean: true,
  15. },
  16. plugins: [
  17. {
  18. name: "@hey-api/typescript",
  19. exportFromIndex: false,
  20. },
  21. {
  22. name: "@hey-api/sdk",
  23. instance: "OpencodeClient",
  24. exportFromIndex: false,
  25. auth: false,
  26. paramsStructure: "flat",
  27. },
  28. {
  29. name: "@hey-api/client-fetch",
  30. exportFromIndex: false,
  31. baseUrl: "http://localhost:4096",
  32. },
  33. ],
  34. })
  35. await $`bun prettier --write src/gen`
  36. await $`bun prettier --write src/v2`
  37. await $`rm -rf dist`
  38. await $`bun tsc`
  39. await $`rm openapi.json`