Files
nextjs-style-guide/concat-md.js

89 lines
2.3 KiB
JavaScript
Raw Normal View History

2026-03-28 21:15:15 +03:00
import { concatMdSync } from "concat-md";
2025-07-25 00:11:30 +03:00
import path from "path";
import fs from "fs";
2026-03-28 21:15:15 +03:00
// Явный порядок файлов внутри каждого языка
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;
2025-07-25 00:11:30 +03:00
}
2026-03-28 21:15:15 +03:00
const content = fs.readFileSync(indexPath, "utf8")
.replace(/^---[\s\S]*?---\n*/m, "");
fs.writeFileSync(outFile, content, "utf8");
console.log(`${outFile} создан из ${indexPath}`);
};
2025-07-25 00:11:30 +03:00
2026-03-28 21:15:15 +03:00
buildReadme("en", "./README.md");
buildReadme("ru", "./README_RU.md");