Files
writer-work-flow/apps/web/scripts/gen-api.mjs
Yaojia Wang d3dc620a71 feat: Phase 0 — monorepo 骨架 + 全表迁移 + FastAPI/Next 骨架 + CI
- uv(workspace) + pnpm monorepo;docker-compose(pg+api+web)
- SQLAlchemy 16 MVP 表 + Alembic 初版迁移(无漂移,users stub)
- FastAPI 骨架:统一错误信封(带 request_id) + structlog + /jobs/:id + OpenAPI
- Next.js 骨架:纸感主题 token + OpenAPI→TS 客户端代码生成(gen:api)
- CI(ruff/mypy/pytest + pg service + alembic 漂移校验)
- 四份设计规格(PRODUCT/UX/ARCHITECTURE/DEV_PLAN) + CLAUDE.md
2026-06-18 11:38:28 +02:00

27 lines
1003 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { execFileSync } from "node:child_process";
import { mkdirSync, writeFileSync } from "node:fs";
import { resolve } from "node:path";
const repoRoot = resolve(import.meta.dirname, "../../..");
const webRoot = resolve(import.meta.dirname, "..");
const outDir = resolve(webRoot, "lib/api");
const jsonPath = resolve(outDir, "openapi.json");
const dtsPath = resolve(outDir, "schema.d.ts");
mkdirSync(outDir, { recursive: true });
// 1) 后端 OpenAPIuv 运行离线CI 无需起服务)
const uv = process.env.UV_BIN ?? "uv";
const spec = execFileSync(uv, ["run", "python", "-m", "ww_api.export_openapi"], {
cwd: repoRoot,
encoding: "utf8",
maxBuffer: 32 * 1024 * 1024,
});
writeFileSync(jsonPath, spec);
// 2) OpenAPI → TS 类型(本地 bin避免 pnpm exec 的工作区检查)
const bin = resolve(webRoot, "node_modules/.bin/openapi-typescript");
execFileSync(bin, [jsonPath, "-o", dtsPath], { cwd: webRoot, stdio: "inherit" });
console.log("gen:api done ->", dtsPath);