Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script to find old source and translations content #10111

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"lint:slugcheck": "node ./scripts/lint-slugcheck.mjs",
"lint:eslint": "eslint .",
"netlify:build": "pnpm ${NETLIFY_BUILD_SCRIPT:-build}",
"lunaria:build": "tsm ./scripts/lunaria.mts"
"lunaria:build": "tsm ./scripts/lunaria.mts",
"lunaria:old-translations": "node ./scripts/old-translations.mjs",
"lunaria:old-source": "node ./scripts/old-source.mjs"
},
"devDependencies": {
"@11ty/eleventy-fetch": "^3.0.0",
Expand Down Expand Up @@ -68,7 +70,7 @@
"@astrojs/starlight": "^0.29.1",
"@docsearch/js": "^3.5.2",
"@expressive-code/plugin-collapsible-sections": "^0.38.3",
"@lunariajs/core": "https://pkg.pr.new/lunariajs/lunaria/@lunariajs/core@62a858f",
"@lunariajs/core": "https://pkg.pr.new/lunariajs/lunaria/@lunariajs/core@4c8b9b0",
"canvas-confetti": "^1.6.0",
"jsdoc-api": "^9.3.4",
"rehype-autolink-headings": "^7.1.0",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scripts/lunaria/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export const LocaleDetails = (
</ul>`
: ''}
${missingFiles.length == 0 && outdatedFiles.length == 0
? html`<p>"This translation is complete, amazing job! 🎉"</p>`
? html`<p>This translation is complete, amazing job! 🎉</p>`
: ''}
</details>
`;
Expand Down
34 changes: 34 additions & 0 deletions scripts/old-source.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { createLunaria } from '@lunariajs/core';
import { yellow, blue } from 'kleur/colors';

// Set the amount of days since the last update in a source file.
const DAYS_TO_OUTDATED_MARK = parseInt(process.argv[2]) || 180;

console.log('Loading status from Lunaria...');

const lunaria = await createLunaria();
const status = await lunaria.getFullStatus();

const outdatedLog = [];

for (const { source } of status) {
const latestSourceUpdate = new Date(source.git.latestTrackedChange.date);
const daysSinceLastUpdate = Math.round(
(Date.now() - latestSourceUpdate.getTime()) / (1000 * 60 * 60 * 24)
);

if (daysSinceLastUpdate >= DAYS_TO_OUTDATED_MARK) {
outdatedLog.push(`- ${blue(source.path)} (${yellow(daysSinceLastUpdate)} days)`);
}
}

if (outdatedLog.length > 0) {
console.log(
`Found ${yellow(outdatedLog.length)} source files that haven't been updated in ${yellow(DAYS_TO_OUTDATED_MARK)} days or more:`
);
outdatedLog.forEach((log) => console.log(log));
} else {
console.log(
`Found no source files that haven't been updated in ${yellow(DAYS_TO_OUTDATED_MARK)} days or more!`
);
}
51 changes: 51 additions & 0 deletions scripts/old-translations.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { createLunaria } from '@lunariajs/core';
import { unlinkSync } from 'node:fs';
import { yellow, blue, red } from 'kleur/colors';

// Set the amount of days between the last update in the source file
// and a translation to be considered an old translation. Default: 180 (6 months)
// Can be set by passing a number as the first argument when running the script.
const DAYS_TO_OUTDATED_MARK = parseInt(process.argv[2]) || 180;
// Set if the outdated files should be removed. Default: false
// Can be set by passing -r as an argument when running the script.
const REMOVE_OUTDATED_FILES = process.argv[2] === '-r' || process.argv[3] === '-r';

console.log('Loading status from Lunaria...');

const lunaria = await createLunaria();
const status = await lunaria.getFullStatus();

const outdatedLog = [];

for (const { source, localizations } of status) {
const latestSourceUpdate = new Date(source.git.latestTrackedChange.date);

for (const localization of localizations) {
if (localization.status !== 'outdated') continue;

const latestTranslationUpdate = new Date(localization.git.latestTrackedChange.date);
const daysSinceLastUpdate = Math.round(
(latestSourceUpdate.getTime() - latestTranslationUpdate.getTime()) / (1000 * 60 * 60 * 24)
);

if (daysSinceLastUpdate >= DAYS_TO_OUTDATED_MARK) {
if (REMOVE_OUTDATED_FILES) {
unlinkSync(localization.path);
}
outdatedLog.push(
`- ${blue(localization.path)} (${yellow(daysSinceLastUpdate)} days) ${REMOVE_OUTDATED_FILES ? red('[REMOVED]') : ''}`
);
}
}
}

if (outdatedLog.length > 0) {
console.log(
`Found ${yellow(outdatedLog.length)} translations that haven't been updated in ${yellow(DAYS_TO_OUTDATED_MARK)} days or more:`
);
outdatedLog.forEach((log) => console.log(log));
} else {
console.log(
`Found no translations that haven't been updated in ${yellow(DAYS_TO_OUTDATED_MARK)} days or more!`
);
}
Loading