29 lines
1.2 KiB
JavaScript
29 lines
1.2 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* sync-openapi.mjs — holt die OpenAPI-Spec vom laufenden Tibi-Server
|
|
* und legt sie als Referenz-Seite ab. Ohne laufenden Server: Platzhalter.
|
|
* Aufruf: npm run sync:openapi
|
|
* Env: TIBI_API_URL (default http://localhost:8080/api), TIBI_NAMESPACE
|
|
*/
|
|
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
import { dirname, join } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const root = join(dirname(fileURLToPath(import.meta.url)), '..');
|
|
const base = process.env.TIBI_API_URL ?? 'http://localhost:8080/api';
|
|
const out = join(root, 'src', 'content', 'docs', 'reference', 'openapi.md');
|
|
|
|
try {
|
|
const res = await fetch(`${base}/openapi.json`);
|
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
const spec = await res.text();
|
|
mkdirSync(dirname(out), { recursive: true });
|
|
writeFileSync(
|
|
out,
|
|
`---\ntitle: 'OpenAPI (generiert)'\n---\n\n> Stand: ${new Date().toISOString()} · Quelle: \`${base}/openapi.json\` — nicht von Hand editieren.\n\n\`\`\`json\n${spec.slice(0, 20000)}\n\`\`\`\n\n_Volle Spec: \`${base}/openapi.json\`_\n`,
|
|
);
|
|
console.log(`[sync:openapi] geschrieben: ${out}`);
|
|
} catch (err) {
|
|
console.warn(`[sync:openapi] Server nicht erreichbar (${base}): ${err.message} — Platzhalter bleibt.`);
|
|
}
|