sync
This commit is contained in:
99
concat-md.js
99
concat-md.js
@@ -1,23 +1,88 @@
|
||||
import concatMd, { concatMdSync } from "concat-md";
|
||||
import { concatMdSync } from "concat-md";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
|
||||
const resultMd = concatMdSync("./parts", {
|
||||
toc: false,
|
||||
sorter: (a, b) => {
|
||||
// Извлекаем номер из начала имени файла (например, "1" из "1-assistent.md")
|
||||
const getNumber = (filename) => {
|
||||
const match = filename.match(/^(\d+)/);
|
||||
return match ? parseInt(match[1], 10) : 0;
|
||||
};
|
||||
|
||||
// Сортировка по возрастанию (1, 2, 3...)
|
||||
return getNumber(a) - getNumber(b);
|
||||
// Явный порядок файлов внутри каждого языка
|
||||
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;
|
||||
}
|
||||
});
|
||||
|
||||
// Записываем результат в файл RULES.md в корне проекта
|
||||
const outputPath = path.join("./", "RULES.md");
|
||||
fs.writeFileSync(outputPath, resultMd, "utf8");
|
||||
fs.mkdirSync(outDir, { recursive: true });
|
||||
|
||||
console.log(`Файл RULES.md успешно создан: ${outputPath}`);
|
||||
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");
|
||||
|
||||
Reference in New Issue
Block a user