import { concatMdSync } from "concat-md"; import path from "path"; import fs from "fs"; // Явный порядок файлов внутри каждого языка const fileOrder = [ // index "index.md", // workflow "workflow/getting-started.md", "workflow/creating-app.md", "workflow/creating-pages.md", "workflow/creating-components.md", "workflow/styling.md", "workflow/data-fetching.md", "workflow/state-management.md", "workflow/localization.md", // basics "basics/tech-stack.md", "basics/architecture.md", "basics/code-style.md", "basics/naming.md", "basics/documentation.md", "basics/typing.md", // applied "applied/project-structure.md", "applied/components.md", "applied/templates-generation.md", "applied/styles.md", "applied/images-sprites.md", "applied/svg-sprites.md", "applied/video.md", "applied/api.md", "applied/stores.md", "applied/hooks.md", "applied/fonts.md", "applied/localization.md", ]; const buildRules = (lang) => { const srcDir = `./docs/${lang}`; const outDir = `./generated/${lang}`; const outFile = path.join(outDir, "RULES.md"); if (!fs.existsSync(srcDir)) { console.log(`Пропуск ${lang}: папка ${srcDir} не найдена`); return; } fs.mkdirSync(outDir, { recursive: true }); const resultMd = concatMdSync(srcDir, { toc: false, sorter: (a, b) => { const indexA = fileOrder.indexOf(a); const indexB = fileOrder.indexOf(b); const posA = indexA === -1 ? fileOrder.length : indexA; const posB = indexB === -1 ? fileOrder.length : indexB; return posA - posB; }, }); fs.writeFileSync(outFile, resultMd, "utf8"); console.log(`RULES.md (${lang}) создан: ${outFile}`); }; // Собираем RULES.md для обоих языков buildRules("ru"); buildRules("en"); // Генерируем README из index.md const buildReadme = (lang, outFile) => { const indexPath = `./docs/${lang}/index.md`; if (!fs.existsSync(indexPath)) { console.log(`Пропуск README (${lang}): ${indexPath} не найден`); return; } const content = fs.readFileSync(indexPath, "utf8") .replace(/^---[\s\S]*?---\n*/m, ""); fs.writeFileSync(outFile, content, "utf8"); console.log(`${outFile} создан из ${indexPath}`); }; buildReadme("en", "./README.md"); buildReadme("ru", "./README_RU.md");