Files
upstream-twenty/packages/twenty-docs/scripts/prune-orphan-translations.ts
upstream-mirror e7da97194a
Some checks failed
App Prod-Parity E2E Dispatch / dispatch (push) Failing after 10s
CD Storybook UI / build (push) Failing after 3m25s
CD Storybook UI / dispatch (push) Has been skipped
CD deploy main / website-changed-files (push) Successful in 18m8s
CI Agent Skills / changed-files-check (push) Successful in 18m9s
CI Create App E2E minimal / changed-files-check (push) Successful in 24s
CI Create App / changed-files-check (push) Successful in 26s
CI Docs / changed-files-check (push) Successful in 26s
CI Emails / changed-files-check (push) Successful in 28s
CI Example App Hello World / changed-files-check (push) Successful in 23s
CI Front / changed-files-check (push) Has been skipped
CI Example App Postcard / changed-files-check (push) Successful in 27s
CI UI / changed-files-check (push) Has been skipped
CI Utils Test / changed-files-check (push) Successful in 45s
CI Twenty Apps / discover (push) Successful in 1m3s
CD deploy main / deploy-main (push) Failing after 3s
CI Agent Skills / agent-skills-validate (push) Has been skipped
CI Create App / create-app-test (lint) (push) Has been skipped
CI Emails / emails-test (push) Has been skipped
CI Front / front-task (lingui:compile) (push) Has been skipped
CI Front / front-task (lint) (push) Has been skipped
CI Example App Postcard / example-app-postcard (push) Has been skipped
CI UI / ui-task (lint) (push) Has been skipped
CI UI / ui-task (pack-size) (push) Has been skipped
CI UI / ui-task (size) (push) Has been skipped
CI UI / ui-task (test) (push) Has been skipped
CI UI / ui-task (typecheck) (push) Has been skipped
CI Utils Test / utils-test (push) Has been skipped
CI Twenty Apps / ${{ matrix.app.name }} (push) Has been skipped
CI Emails / ci-emails-status-check (push) Successful in 2s
CI Example App Hello World / ci-example-app-hello-world-status-check (push) Successful in 2s
CI Example App Postcard / ci-example-app-postcard-status-check (push) Successful in 3s
CI UI / ui-sb-test (push) Has been skipped
CI Utils Test / ci-utils-test-status-check (push) Successful in 2s
CI Twenty Apps / ci-twenty-apps-status-check (push) Successful in 2s
CI UI / ci-ui-status-check (push) Successful in 2s
CI Desktop / desktop (push) Failing after 1m8s
Push docs to Crowdin / Push documentation to Crowdin (push) Failing after 55s
Push translations to Crowdin / Extract and upload translations (push) Failing after 5s
Push website translations to Crowdin / Extract and upload website translations (push) Failing after 5s
CI Create App / create-app-test (test) (push) Has been skipped
CI Create App / create-app-test (typecheck) (push) Has been skipped
CI Docs / docs-lint (push) Has been skipped
CI Example App Hello World / example-app-hello-world (push) Has been skipped
CI Front / front-task (lingui:extract) (push) Has been skipped
CI Front / front-task (test) (push) Has been skipped
CI Front / front-task (typecheck) (push) Has been skipped
CI UI / ui-sb-build (push) Failing after 1m32s
CI Twenty Apps / ${{ matrix.app.name }} (${{ matrix.server-source }}) (push) Has been skipped
CI Agent Skills / agent-skills-publish (push) Has been skipped
CI Create App / ci-create-app-status-check (push) Successful in 2s
CI Agent Skills / agent-skills-remote-source (push) Has been skipped
CI Create App E2E minimal / create-app-e2e-minimal (push) Has been cancelled
CI E2E Main / e2e-test (push) Has been cancelled
CI Front / front-sb-build (push) Has been cancelled
CI Front / front-build (push) Has been cancelled
CI Create App E2E minimal / ci-create-app-e2e-minimal-status-check (push) Has been cancelled
CI E2E Main / ci-e2e-main-status-check (push) Has been cancelled
CI E2E Main / notify-main-ci-failure (push) Has been cancelled
CI E2E Main / qa-scout-comment (push) Has been cancelled
CI Front / front-sb-test (push) Has been cancelled
CI Front / front-sb-screenshots (push) Has been cancelled
CI Front / ci-front-status-check (push) Has been cancelled
DPA Sub-Processor Sync / sync-subprocessors (push) Failing after 3s
AI Catalog Sync / sync-catalog (push) Failing after 2s
snapshot of https://github.com/twentyhq/twenty.git (main, 2026-09-17; blobs > 131072B omitted)
2026-09-17 23:28:13 +05:00

117 lines
4.2 KiB
TypeScript

import fs from 'fs';
import path from 'path';
// Removes orphan localized docs: files under packages/twenty-docs/l/<lang>/**
// whose corresponding English source page no longer exists. The Crowdin i18n
// pull only ever adds/updates files (never deletes), so when an English page is
// renamed, moved, or removed, its localized copies linger and keep serving
// dead/stale URLs. This keeps the localized tree in sync with the source tree.
//
// DRY-RUN by default (prints what it would remove); pass --apply to delete.
//
// Usage:
// tsx packages/twenty-docs/scripts/prune-orphan-translations.ts
// tsx packages/twenty-docs/scripts/prune-orphan-translations.ts --apply
const DOCS_ROOT = path.resolve(__dirname, '..');
const LOCALIZED_DIR = path.join(DOCS_ROOT, 'l');
// Safety: never delete a language's localized files wholesale. If more than this
// fraction of a language's files look orphaned, something is wrong (e.g. the
// English source tree wasn't checked out) — abort instead of pruning.
const MAX_ORPHAN_RATIO_PER_LANGUAGE = 0.25;
const apply = process.argv.slice(2).includes('--apply');
const walkMdxFiles = (dir: string): string[] => {
const result: string[] = [];
for (const entry of fs.readdirSync(dir)) {
const fullPath = path.join(dir, entry);
if (fs.statSync(fullPath).isDirectory()) {
result.push(...walkMdxFiles(fullPath));
} else if (entry.endsWith('.mdx')) {
result.push(fullPath);
}
}
return result;
};
// English source path a localized file mirrors: strip the leading `l/<lang>/`.
const sourcePathOf = (localizedFile: string): string => {
const relativeToL = path.relative(LOCALIZED_DIR, localizedFile);
const segments = relativeToL.split(path.sep);
// segments[0] is the language code; the rest is the source-relative path.
return path.join(DOCS_ROOT, ...segments.slice(1));
};
const languageOf = (localizedFile: string): string =>
path.relative(LOCALIZED_DIR, localizedFile).split(path.sep)[0];
const main = (): void => {
if (!fs.existsSync(LOCALIZED_DIR)) {
console.log('No localized docs directory (packages/twenty-docs/l) — nothing to prune.');
return;
}
// Sanity guard: if the English source tree is empty, the checkout is broken;
// refuse to prune so we never mass-delete translations by mistake.
const englishFileCount = walkMdxFiles(DOCS_ROOT).filter(
(file) => !file.startsWith(`${LOCALIZED_DIR}${path.sep}`),
).length;
if (englishFileCount === 0) {
throw new Error(
'Refusing to prune: found 0 English source .mdx files (source tree missing?).',
);
}
const localizedFiles = walkMdxFiles(LOCALIZED_DIR);
const orphans = localizedFiles.filter(
(file) => !fs.existsSync(sourcePathOf(file)),
);
if (orphans.length === 0) {
console.log(`No orphan localized files (${localizedFiles.length} scanned).`);
return;
}
// Per-language blast-radius check.
const filesByLanguage = new Map<string, number>();
const orphansByLanguage = new Map<string, number>();
for (const file of localizedFiles) {
const language = languageOf(file);
filesByLanguage.set(language, (filesByLanguage.get(language) ?? 0) + 1);
}
for (const file of orphans) {
const language = languageOf(file);
orphansByLanguage.set(language, (orphansByLanguage.get(language) ?? 0) + 1);
}
for (const [language, orphanCount] of orphansByLanguage) {
const total = filesByLanguage.get(language) ?? 0;
const ratio = total === 0 ? 1 : orphanCount / total;
if (ratio > MAX_ORPHAN_RATIO_PER_LANGUAGE) {
throw new Error(
`Refusing to prune: ${orphanCount}/${total} (${Math.round(ratio * 100)}%) of "${language}" files look orphaned, ` +
`over the ${Math.round(MAX_ORPHAN_RATIO_PER_LANGUAGE * 100)}% safety cap. Check the source checkout before pruning.`,
);
}
}
console.log(
`${apply ? 'Removing' : 'Would remove'} ${orphans.length} orphan localized file(s) of ${localizedFiles.length} scanned:`,
);
for (const file of orphans.sort()) {
console.log(` ${apply ? 'DELETE' : 'orphan'} ${path.relative(DOCS_ROOT, file)}`);
if (apply) {
fs.rmSync(file);
}
}
console.log(
`${apply ? 'Removed' : 'Would remove'}: ${orphans.length} file(s) across ${orphansByLanguage.size} language(s).`,
);
};
main();