Spaces:
Running
Running
File size: 1,536 Bytes
9de795a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | /**
* Generiert TS-Typen aus den JSON-Schemas (schemas/ → src/generated/).
* Die pydantic-Seite erzeugt services/engines/scripts/codegen.py.
* Generierte Files NIE von Hand ändern. Aufruf: pnpm codegen
*/
import { compileFromFile } from "json-schema-to-typescript";
import { mkdirSync, readdirSync, writeFileSync } from "node:fs";
import { join, dirname, resolve, basename } from "node:path";
import { fileURLToPath } from "node:url";
const here = dirname(fileURLToPath(import.meta.url));
const schemasDir = resolve(here, "../schemas");
const outDir = resolve(here, "../src/generated");
mkdirSync(outDir, { recursive: true });
const banner =
"/* AUTOGENERIERT aus packages/shared/schemas – nicht von Hand ändern (pnpm codegen). */\n\n";
const indexLines: string[] = [];
for (const file of readdirSync(schemasDir).filter((f) => f.endsWith(".schema.json"))) {
const name = basename(file, ".schema.json");
const ts = await compileFromFile(join(schemasDir, file), {
cwd: schemasDir,
bannerComment: "",
additionalProperties: false,
});
writeFileSync(join(outDir, `${name}.ts`), banner + ts);
// Namespace-Export: jedes Schema bringt eigene $defs (Uuid, Pose, …) mit –
// Stern-Re-Exports würden kollidieren.
const ns = name.replace(/-([a-z])/g, (_, c: string) => (c as string).toUpperCase());
indexLines.push(`export * as ${ns} from "./${name}.ts";`);
console.log(`✅ ${file} → src/generated/${name}.ts`);
}
writeFileSync(join(outDir, "index.ts"), banner + indexLines.join("\n") + "\n");
|