From 0356ebba0e29e362489b85e511fa818769228910 Mon Sep 17 00:00:00 2001 From: Yan <61414485+yanthomasdev@users.noreply.github.com> Date: Wed, 27 Nov 2024 14:22:01 -0300 Subject: [PATCH 1/5] Update Lunaria version --- package.json | 2 +- pnpm-lock.yaml | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 751acac04839f..7ff4be6435ecd 100644 --- a/package.json +++ b/package.json @@ -70,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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 658a8f20a8c74..ff4b6359a583c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -24,8 +24,8 @@ importers: specifier: ^0.38.3 version: 0.38.3 '@lunariajs/core': - specifier: https://pkg.pr.new/lunariajs/lunaria/@lunariajs/core@62a858f - version: https://pkg.pr.new/lunariajs/lunaria/@lunariajs/core@62a858f + specifier: https://pkg.pr.new/lunariajs/lunaria/@lunariajs/core@4c8b9b0 + version: https://pkg.pr.new/lunariajs/lunaria/@lunariajs/core@4c8b9b0 canvas-confetti: specifier: ^1.6.0 version: 1.6.0 @@ -778,8 +778,8 @@ packages: '@kwsites/promise-deferred@1.1.1': resolution: {integrity: sha512-GaHYm+c0O9MjZRu0ongGBRbinu8gVAMd2UZjji6jVmqKtZluZnptXGWhz1E8j8D2HJ3f/yMxKAUC0b+57wncIw==} - '@lunariajs/core@https://pkg.pr.new/lunariajs/lunaria/@lunariajs/core@62a858f': - resolution: {tarball: https://pkg.pr.new/lunariajs/lunaria/@lunariajs/core@62a858f} + '@lunariajs/core@https://pkg.pr.new/lunariajs/lunaria/@lunariajs/core@4c8b9b0': + resolution: {tarball: https://pkg.pr.new/lunariajs/lunaria/@lunariajs/core@4c8b9b0} version: 0.1.1 engines: {node: '>=18.17.0'} @@ -4565,7 +4565,7 @@ snapshots: '@kwsites/promise-deferred@1.1.1': {} - '@lunariajs/core@https://pkg.pr.new/lunariajs/lunaria/@lunariajs/core@62a858f': + '@lunariajs/core@https://pkg.pr.new/lunariajs/lunaria/@lunariajs/core@4c8b9b0': dependencies: consola: 3.2.3 jiti: 2.3.3 From 3c33339f154c9f04f42000c3cf8a31b86f726968 Mon Sep 17 00:00:00 2001 From: Yan <61414485+yanthomasdev@users.noreply.github.com> Date: Wed, 27 Nov 2024 14:30:33 -0300 Subject: [PATCH 2/5] Fix accidental quotes in dashboard paragraph --- lunaria/components.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lunaria/components.ts b/lunaria/components.ts index 41b9e1fdc9f02..543e1ba5684a3 100644 --- a/lunaria/components.ts +++ b/lunaria/components.ts @@ -155,7 +155,7 @@ export const LocaleDetails = ( ` : ''} ${missingFiles.length == 0 && outdatedFiles.length == 0 - ? html`
"This translation is complete, amazing job! 🎉"
` + ? html`This translation is complete, amazing job! 🎉
` : ''} `; From 3d7015bb288a7c9e0302b494d9de8745fc4a745e Mon Sep 17 00:00:00 2001 From: Yan <61414485+yanthomasdev@users.noreply.github.com> Date: Wed, 27 Nov 2024 15:14:48 -0300 Subject: [PATCH 3/5] Add script to find and delete old translations --- package.json | 3 ++- scripts/old-translations.mjs | 49 ++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 scripts/old-translations.mjs diff --git a/package.json b/package.json index 7ff4be6435ecd..596036300196a 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "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" }, "devDependencies": { "@11ty/eleventy-fetch": "^3.0.0", diff --git a/scripts/old-translations.mjs b/scripts/old-translations.mjs new file mode 100644 index 0000000000000..b8479f22480e4 --- /dev/null +++ b/scripts/old-translations.mjs @@ -0,0 +1,49 @@ +import { createLunaria } from '@lunariajs/core'; +import { unlinkSync } from 'node:fs'; +// 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( + `- ${localization.path} (${daysSinceLastUpdate} days) ${REMOVE_OUTDATED_FILES ? '[removed]' : ''}` + ); + } + } +} + +if (outdatedLog.length > 0) { + console.log( + `Found ${outdatedLog.length} translations that haven't been updated in ${DAYS_TO_OUTDATED_MARK} days:` + ); + outdatedLog.forEach((log) => console.log(log)); +} else { + console.log( + `Found no translations that haven't been updated in less than ${DAYS_TO_OUTDATED_MARK} days!` + ); +} From e3809b88a52946ff9cdfb7d164d0cca14bc83ee1 Mon Sep 17 00:00:00 2001 From: Yan <61414485+yanthomasdev@users.noreply.github.com> Date: Thu, 12 Dec 2024 17:00:40 -0300 Subject: [PATCH 4/5] Add colors to old-translations script and improve wording --- scripts/old-translations.mjs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/old-translations.mjs b/scripts/old-translations.mjs index b8479f22480e4..9f7dc2929978a 100644 --- a/scripts/old-translations.mjs +++ b/scripts/old-translations.mjs @@ -1,5 +1,7 @@ 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. @@ -31,7 +33,7 @@ for (const { source, localizations } of status) { unlinkSync(localization.path); } outdatedLog.push( - `- ${localization.path} (${daysSinceLastUpdate} days) ${REMOVE_OUTDATED_FILES ? '[removed]' : ''}` + `- ${blue(localization.path)} (${yellow(daysSinceLastUpdate)} days) ${REMOVE_OUTDATED_FILES ? red('[REMOVED]') : ''}` ); } } @@ -39,11 +41,11 @@ for (const { source, localizations } of status) { if (outdatedLog.length > 0) { console.log( - `Found ${outdatedLog.length} translations that haven't been updated in ${DAYS_TO_OUTDATED_MARK} days:` + `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 less than ${DAYS_TO_OUTDATED_MARK} days!` + `Found no translations that haven't been updated in ${yellow(DAYS_TO_OUTDATED_MARK)} days or more!` ); } From b38e7293fe276c2a533d29165000a61805815855 Mon Sep 17 00:00:00 2001 From: Yan <61414485+yanthomasdev@users.noreply.github.com> Date: Thu, 12 Dec 2024 17:00:54 -0300 Subject: [PATCH 5/5] Add companion script to find old source files --- package.json | 3 ++- scripts/old-source.mjs | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 scripts/old-source.mjs diff --git a/package.json b/package.json index 596036300196a..f3c3714488cee 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,8 @@ "lint:eslint": "eslint .", "netlify:build": "pnpm ${NETLIFY_BUILD_SCRIPT:-build}", "lunaria:build": "tsm ./scripts/lunaria.mts", - "lunaria:old-translations": "node ./scripts/old-translations.mjs" + "lunaria:old-translations": "node ./scripts/old-translations.mjs", + "lunaria:old-source": "node ./scripts/old-source.mjs" }, "devDependencies": { "@11ty/eleventy-fetch": "^3.0.0", diff --git a/scripts/old-source.mjs b/scripts/old-source.mjs new file mode 100644 index 0000000000000..f430d707529e5 --- /dev/null +++ b/scripts/old-source.mjs @@ -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!` + ); +}