feat: complete tenant learning and admin experience
This commit is contained in:
32
scripts/generate-api.mjs
Normal file
32
scripts/generate-api.mjs
Normal file
@@ -0,0 +1,32 @@
|
||||
import { execFileSync } from "node:child_process";
|
||||
import { mkdirSync, writeFileSync } from "node:fs";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import path from "node:path";
|
||||
|
||||
const projectRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
||||
const openApiUrl = process.env.OPENAPI_URL || "http://localhost:5090/openapi/v1.json";
|
||||
const response = await fetch(openApiUrl);
|
||||
if (!response.ok) {
|
||||
throw new Error(`OpenAPI 下载失败:${response.status} ${response.statusText}`);
|
||||
}
|
||||
|
||||
const document = await response.json();
|
||||
const generatedDir = path.join(projectRoot, ".generated");
|
||||
const apiDir = path.join(projectRoot, "src", "api");
|
||||
mkdirSync(generatedDir, { recursive: true });
|
||||
mkdirSync(apiDir, { recursive: true });
|
||||
|
||||
const snapshotPath = path.join(generatedDir, "openapi.json");
|
||||
writeFileSync(snapshotPath, `${JSON.stringify(document)}\n`);
|
||||
|
||||
const cli = path.join(
|
||||
projectRoot,
|
||||
"node_modules",
|
||||
".bin",
|
||||
process.platform === "win32" ? "openapi-typescript.cmd" : "openapi-typescript",
|
||||
);
|
||||
execFileSync(cli, [snapshotPath, "-o", path.join(apiDir, "schema.generated.d.ts")], {
|
||||
stdio: "inherit",
|
||||
});
|
||||
|
||||
console.log(`已生成前端 OpenAPI 类型,来源:${openApiUrl}`);
|
||||
Reference in New Issue
Block a user