#!/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.`); }