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
This commit is contained in:
26
apps/web/scripts/gen-api.mjs
Normal file
26
apps/web/scripts/gen-api.mjs
Normal file
@@ -0,0 +1,26 @@
|
||||
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) 后端 OpenAPI(uv 运行,离线,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);
|
||||
Reference in New Issue
Block a user