1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Tools: Display deleted strings when building translations, and run TypeScript before

This commit is contained in:
Laurent Cozic 2020-11-08 17:19:38 +00:00
parent 5269a4b7fa
commit 498e80f2d3
3 changed files with 27 additions and 4 deletions

View File

@ -10,7 +10,7 @@
"buildApiDoc": "npm start --prefix=packages/app-cli -- apidoc ../../readme/api/references/rest_api.md", "buildApiDoc": "npm start --prefix=packages/app-cli -- apidoc ../../readme/api/references/rest_api.md",
"buildDoc": "./packages/tools/build-all.sh", "buildDoc": "./packages/tools/build-all.sh",
"buildPluginDoc": "typedoc --name 'Joplin Plugin API Documentation' --mode file -theme './Assets/PluginDocTheme/' --readme './Assets/PluginDocTheme/index.md' --excludeNotExported --excludeExternals --excludePrivate --excludeProtected --out docs/api/references/plugin_api packages/lib/services/plugins/api/", "buildPluginDoc": "typedoc --name 'Joplin Plugin API Documentation' --mode file -theme './Assets/PluginDocTheme/' --readme './Assets/PluginDocTheme/index.md' --excludeNotExported --excludeExternals --excludePrivate --excludeProtected --out docs/api/references/plugin_api packages/lib/services/plugins/api/",
"buildTranslations": "node packages/tools/build-translation.js", "buildTranslations": "npm run tsc && node packages/tools/build-translation.js",
"buildWebsite": "npm run buildApiDoc && node ./packages/tools/build-website.js && npm run buildPluginDoc", "buildWebsite": "npm run buildApiDoc && node ./packages/tools/build-website.js && npm run buildPluginDoc",
"clean": "lerna clean -y && lerna run clean", "clean": "lerna clean -y && lerna run clean",
"generatePluginTypes": "rm -rf ./plugin_types && node node_modules/typescript/bin/tsc --declaration --declarationDir ./plugin_types --project tsconfig.json", "generatePluginTypes": "rm -rf ./plugin_types && node node_modules/typescript/bin/tsc --declaration --declarationDir ./plugin_types --project tsconfig.json",

View File

@ -1,3 +1,4 @@
*-kct.* *-kct.*
github_username_cache.json github_username_cache.json
patreon_oauth_token.txt patreon_oauth_token.txt
*.po~

View File

@ -90,6 +90,7 @@ async function createPotFile(potFilePath) {
'./packages/app-cli/tests-build/*', './packages/app-cli/tests-build/*',
'./packages/app-cli/tests/*', './packages/app-cli/tests/*',
'./packages/app-clipper/*', './packages/app-clipper/*',
'./packages/fork-*/*',
'./packages/app-desktop/dist/*', './packages/app-desktop/dist/*',
'./packages/app-desktop/gui/note-viewer/pluginAssets/*', './packages/app-desktop/gui/note-viewer/pluginAssets/*',
'./packages/app-desktop/gui/style/*', './packages/app-desktop/gui/style/*',
@ -285,6 +286,20 @@ async function updateReadmeWithStats(stats) {
); );
} }
async function translationStrings(poFilePath) {
const r = await parsePoFile(poFilePath);
return Object.keys(r.translations['']);
}
function deletedStrings(oldStrings, newStrings) {
const output = [];
for (const s1 of oldStrings) {
if (newStrings.includes(s1)) continue;
output.push(s1);
}
return output;
}
async function main() { async function main() {
const argv = require('yargs').argv; const argv = require('yargs').argv;
@ -292,20 +307,27 @@ async function main() {
const jsonLocalesDir = `${libDir}/locales`; const jsonLocalesDir = `${libDir}/locales`;
const defaultLocale = 'en_GB'; const defaultLocale = 'en_GB';
const oldStrings = await translationStrings(potFilePath);
const oldPotStatus = await translationStatus(false, potFilePath); const oldPotStatus = await translationStatus(false, potFilePath);
await createPotFile(potFilePath); await createPotFile(potFilePath);
const newStrings = await translationStrings(potFilePath);
const newPotStatus = await translationStatus(false, potFilePath); const newPotStatus = await translationStatus(false, potFilePath);
console.info(`Updated pot file. Total strings: ${oldPotStatus.untranslatedCount} => ${newPotStatus.untranslatedCount}`); console.info(`Updated pot file. Total strings: ${oldPotStatus.untranslatedCount} => ${newPotStatus.untranslatedCount}`);
const deletedCount = oldPotStatus.untranslatedCount - newPotStatus.untranslatedCount; const deletedCount = oldPotStatus.untranslatedCount - newPotStatus.untranslatedCount;
if (deletedCount >= 10) { if (deletedCount >= 5) {
if (argv['skip-missing-strings-check']) { if (argv['skip-missing-strings-check']) {
console.info(`${deletedCount} strings have been deleted, but proceeding anyway due to --skip-missing-strings-check flag`); console.info(`${deletedCount} strings have been deleted, but proceeding anyway due to --skip-missing-strings-check flag`);
} else { } else {
throw new Error(`${deletedCount} strings have been deleted - aborting as it could be a bug. To override, use the --skip-missing-strings-check flag.`); const msg = [`${deletedCount} strings have been deleted - aborting as it could be a bug. To override, use the --skip-missing-strings-check flag.`];
msg.push('');
msg.push('Deleted strings:');
msg.push('');
msg.push(deletedStrings(oldStrings, newStrings).map(s => `"${s}"`).join('\n'));
throw new Error(msg.join('\n'));
} }
} }