mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-20 14:12:59 +03:00
committed by
GitHub
parent
08e18867fd
commit
3d75fb3fae
@@ -7,6 +7,8 @@ const cwd = process.cwd();
|
||||
const packageJsonPath = path.resolve(cwd, "package.json");
|
||||
const openApiPath = path.resolve(cwd, "docs/openapi.yaml");
|
||||
const changelogPath = path.resolve(cwd, "CHANGELOG.md");
|
||||
const llmPath = path.resolve(cwd, "llm.txt");
|
||||
const i18nDocsPath = path.resolve(cwd, "docs/i18n");
|
||||
|
||||
function readText(filePath) {
|
||||
if (!fs.existsSync(filePath)) {
|
||||
@@ -47,6 +49,23 @@ function extractChangelogSections(content) {
|
||||
return headings.map((match) => match[1]);
|
||||
}
|
||||
|
||||
function stripTopHeading(content) {
|
||||
return content.replace(/^# .+\r?\n+/, "");
|
||||
}
|
||||
|
||||
function extractI18nMirrorBody(content) {
|
||||
const separator = content.match(/^---\s*$/m);
|
||||
if (!separator || separator.index === undefined) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return content.slice(separator.index + separator[0].length).replace(/^\r?\n+/, "");
|
||||
}
|
||||
|
||||
function normalizeMirrorBody(content) {
|
||||
return content.replace(/\r\n/g, "\n").trim();
|
||||
}
|
||||
|
||||
function isSemver(value) {
|
||||
// Accept X.Y.Z and X.Y.Z-prerelease.N (e.g. 3.0.0-rc.1, 3.0.0-beta.2)
|
||||
return /^\d+\.\d+\.\d+(-[a-zA-Z0-9.]+)?$/.test(value);
|
||||
@@ -59,6 +78,46 @@ function fail(message) {
|
||||
console.error(`[docs-sync] FAIL - ${message}`);
|
||||
}
|
||||
|
||||
function checkI18nMirrorFile(fileName, sourcePath) {
|
||||
if (!fs.existsSync(i18nDocsPath)) {
|
||||
fail("docs/i18n directory is missing");
|
||||
return;
|
||||
}
|
||||
|
||||
const sourceBody = normalizeMirrorBody(stripTopHeading(readText(sourcePath)));
|
||||
const locales = fs
|
||||
.readdirSync(i18nDocsPath, { withFileTypes: true })
|
||||
.filter((entry) => entry.isDirectory())
|
||||
.map((entry) => entry.name)
|
||||
.sort();
|
||||
|
||||
let checked = 0;
|
||||
for (const locale of locales) {
|
||||
const targetPath = path.join(i18nDocsPath, locale, fileName);
|
||||
if (!fs.existsSync(targetPath)) {
|
||||
fail(`docs/i18n/${locale}/${fileName} is missing`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const body = extractI18nMirrorBody(readText(targetPath));
|
||||
if (body === null) {
|
||||
fail(`docs/i18n/${locale}/${fileName} is missing the i18n mirror separator`);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (normalizeMirrorBody(body) !== sourceBody) {
|
||||
fail(`docs/i18n/${locale}/${fileName} differs from root ${fileName}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
checked += 1;
|
||||
}
|
||||
|
||||
if (checked > 0) {
|
||||
console.log(`[docs-sync] ${fileName} i18n mirrors match root content: ${checked} locales`);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const packageJson = JSON.parse(readText(packageJsonPath));
|
||||
const packageVersion = packageJson.version;
|
||||
@@ -101,6 +160,9 @@ try {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
checkI18nMirrorFile("llm.txt", llmPath);
|
||||
checkI18nMirrorFile("CHANGELOG.md", changelogPath);
|
||||
} catch (error) {
|
||||
fail(error instanceof Error ? error.message : String(error));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user