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
|
2026-03-29 14:04:19 +03:00
|
|
|
|
"workflow.md",
|
2026-03-28 21:15:15 +03:00
|
|
|
|
// basics
|
|
|
|
|
|
"basics/tech-stack.md",
|
|
|
|
|
|
"basics/architecture.md",
|
|
|
|
|
|
"basics/code-style.md",
|
|
|
|
|
|
"basics/naming.md",
|
|
|
|
|
|
"basics/documentation.md",
|
|
|
|
|
|
"basics/typing.md",
|
|
|
|
|
|
// applied
|
2026-03-29 11:43:23 +03:00
|
|
|
|
"applied/vscode.md",
|
2026-03-28 21:15:15 +03:00
|
|
|
|
"applied/project-structure.md",
|
|
|
|
|
|
"applied/components.md",
|
2026-03-29 11:43:23 +03:00
|
|
|
|
"applied/page-level.md",
|
2026-03-28 21:15:15 +03:00
|
|
|
|
"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",
|
|
|
|
|
|
];
|
|
|
|
|
|
|
2026-03-29 11:43:23 +03:00
|
|
|
|
// Удалить frontmatter из содержимого md-файла
|
|
|
|
|
|
const stripFrontmatter = (content) =>
|
|
|
|
|
|
content.replace(/^---[\s\S]*?---\n*/m, "");
|
|
|
|
|
|
|
|
|
|
|
|
// Сдвинуть уровень заголовков на 1 вниз (h1→h2, h2→h3, ...)
|
|
|
|
|
|
// Не трогает заголовки внутри блоков кода
|
|
|
|
|
|
const shiftHeadings = (content) => {
|
|
|
|
|
|
const lines = content.split("\n");
|
|
|
|
|
|
let inCodeBlock = false;
|
|
|
|
|
|
|
|
|
|
|
|
return lines
|
|
|
|
|
|
.map((line) => {
|
|
|
|
|
|
if (line.startsWith("```")) inCodeBlock = !inCodeBlock;
|
|
|
|
|
|
if (inCodeBlock) return line;
|
|
|
|
|
|
if (/^#{1,5}\s/.test(line)) return "#" + line;
|
|
|
|
|
|
return line;
|
|
|
|
|
|
})
|
|
|
|
|
|
.join("\n");
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Собрать RULES.md с мета-якорями для каждого файла
|
2026-03-28 21:15:15 +03:00
|
|
|
|
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 });
|
|
|
|
|
|
|
2026-03-29 11:43:23 +03:00
|
|
|
|
const parts = [];
|
|
|
|
|
|
|
|
|
|
|
|
for (const file of fileOrder) {
|
|
|
|
|
|
const filePath = path.join(srcDir, file);
|
|
|
|
|
|
if (!fs.existsSync(filePath)) continue;
|
|
|
|
|
|
|
|
|
|
|
|
const raw = fs.readFileSync(filePath, "utf8");
|
|
|
|
|
|
const content = stripFrontmatter(raw).trim();
|
|
|
|
|
|
if (!content) continue;
|
|
|
|
|
|
|
|
|
|
|
|
// Мета-якорь: путь VitePress без расширения
|
|
|
|
|
|
const route = "/" + file.replace(/\.md$/, "");
|
|
|
|
|
|
// index.md остаётся без сдвига (его h1 — главный заголовок документа)
|
|
|
|
|
|
const processed = file === "index.md" ? content : shiftHeadings(content);
|
|
|
|
|
|
parts.push(`<!-- ${route} -->\n${processed}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fs.writeFileSync(outFile, parts.join("\n\n"), "utf8");
|
2026-03-28 21:15:15 +03:00
|
|
|
|
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-29 11:43:23 +03:00
|
|
|
|
const content = stripFrontmatter(fs.readFileSync(indexPath, "utf8"));
|
2026-03-28 21:15:15 +03:00
|
|
|
|
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");
|