import { readFileSync, writeFileSync, readdirSync, statSync } from 'fs'; import { join, dirname } from 'path'; import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); // Paths const DOCS_DIR = join(__dirname, '../docs/en/user-guide'); const OUTPUT_FILE = join(__dirname, '../api/src/lib/setup-knowledge.generated.ts'); function buildSetupKnowledge() { console.log('Building setup knowledge base...'); try { const files = readdirSync(DOCS_DIR).filter(f => f.endsWith('.md')); const knowledge: Record = {}; for (const file of files) { const content = readFileSync(join(DOCS_DIR, file), 'utf-8'); // Store content mapped by filename (e.g. 'GETTING-STARTED.md') knowledge[file] = content; } const outputContent = `// Auto-generated by scripts/build-setup-knowledge.ts // Do not edit manually export const SETUP_KNOWLEDGE: Record = ${JSON.stringify(knowledge, null, 4)}; `; writeFileSync(OUTPUT_FILE, outputContent); console.log(`Successfully generated ${OUTPUT_FILE} with ${Object.keys(knowledge).length} documents.`); } catch (error) { console.error('Failed to build setup knowledge:', error); process.exit(1); } } buildSetupKnowledge();