현재 작업 전체 반영

This commit is contained in:
Yun Chan 2026-06-27 16:08:41 +09:00
parent 5560638e54
commit c0dddab594
85 changed files with 11322 additions and 539 deletions

View file

@ -0,0 +1,57 @@
import { existsSync } from "node:fs";
import { mkdir } from "node:fs/promises";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { spawnSync } from "node:child_process";
const scriptDir = dirname(fileURLToPath(import.meta.url));
const webRoot = resolve(scriptDir, "..");
const repoRoot = resolve(webRoot, "..", "..");
const apiRoot = resolve(repoRoot, "apps", "api");
const schemaPath = resolve(webRoot, "node_modules", ".tmp", "openapi.json");
const outPath = resolve(webRoot, "src", "lib", "api.gen.ts");
const exporter = resolve(apiRoot, "scripts", "export-openapi.py");
const checkOnly = process.argv.includes("--check");
function run(command, args, options = {}) {
const result = spawnSync(command, args, {
cwd: options.cwd ?? webRoot,
env: process.env,
stdio: options.stdio ?? "inherit",
shell: options.shell ?? false,
});
if (result.status === 0) return true;
if (options.allowFailure) return false;
const rendered = [command, ...args].join(" ");
throw new Error(`${rendered} failed with exit code ${result.status}`);
}
async function exportOpenApi() {
await mkdir(dirname(schemaPath), { recursive: true });
const configured = process.env.PYTHON?.trim();
if (configured && run(configured, [exporter, schemaPath], { cwd: apiRoot, allowFailure: true })) {
return;
}
if (process.platform === "win32" && run("py", ["-3.11", exporter, schemaPath], { cwd: apiRoot, allowFailure: true })) {
return;
}
if (run("python", [exporter, schemaPath], { cwd: apiRoot, allowFailure: true })) {
return;
}
throw new Error("Python 3.11 with apps/api dependencies is required to export OpenAPI.");
}
function generateTypes() {
const bin = process.platform === "win32"
? resolve(webRoot, "node_modules", ".bin", "openapi-typescript.cmd")
: resolve(webRoot, "node_modules", ".bin", "openapi-typescript");
if (!existsSync(bin)) {
throw new Error("openapi-typescript is not installed. Run npm install first.");
}
const args = [schemaPath, "-o", outPath];
if (checkOnly) args.push("--check");
run(bin, args, { shell: process.platform === "win32" });
}
await exportOpenApi();
generateTypes();