Add get-prod-locales and lint-locales scripts
This commit is contained in:
parent
318964251d
commit
4f3c2498a6
4 changed files with 100 additions and 38 deletions
|
@ -1,45 +1,49 @@
|
|||
/* eslint-disable no-console */
|
||||
#!/usr/bin/env node
|
||||
|
||||
const { exec } = require('child_process');
|
||||
const cp = require('child_process');
|
||||
const { promisify } = require('util');
|
||||
const fs = require('fs');
|
||||
|
||||
const pkg = require('../package.json');
|
||||
|
||||
const availableLanguages = pkg.availableLanguages.sort();
|
||||
const exec = promisify(cp.exec);
|
||||
|
||||
const compareLocales =
|
||||
'compare-locales l10n.toml . `ls public/locales` --data=json';
|
||||
const arrayDiff = (current, package) =>
|
||||
current.filter(locale => !package.includes(locale));
|
||||
|
||||
exec(compareLocales, (err, stdout, stderr) => {
|
||||
if (err) {
|
||||
const cmd = 'compare-locales l10n.toml . `ls public/locales` --data=json';
|
||||
|
||||
exec(cmd)
|
||||
.then(({ stdout }) => JSON.parse(stdout))
|
||||
.then(({ summary }) => {
|
||||
const locales = Object.keys(summary)
|
||||
.filter(locale => {
|
||||
const loc = summary[locale];
|
||||
const hasMissing = loc.hasOwnProperty('missing');
|
||||
const hasErrors = loc.hasOwnProperty('errors');
|
||||
return !hasMissing && !hasErrors;
|
||||
})
|
||||
.sort();
|
||||
|
||||
if (locales.join(',') !== availableLanguages.join(',')) {
|
||||
const missingLanguages = arrayDiff(locales, availableLanguages);
|
||||
|
||||
console.log('current 100%:', JSON.stringify(locales));
|
||||
console.log('package.json:', JSON.stringify(availableLanguages));
|
||||
console.log('missing prod:', JSON.stringify(missingLanguages));
|
||||
|
||||
if (process.argv.includes('--write')) {
|
||||
const pkgPath = require.resolve('../package.json');
|
||||
pkg.availableLanguages = locales;
|
||||
const str = JSON.stringify(pkg, null, 2) + '\n';
|
||||
console.log('Updating /package.json availableLanguages');
|
||||
fs.writeFileSync(pkgPath, str, 'utf-8');
|
||||
}
|
||||
} else {
|
||||
console.log('Production locales are up to date!');
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
}
|
||||
const missingLocales = (current, package) =>
|
||||
current.filter(locale => !package.includes(locale));
|
||||
const { summary } = JSON.parse(stdout);
|
||||
const locales = Object.keys(summary)
|
||||
.filter(locale => {
|
||||
const loc = summary[locale];
|
||||
const hasMissing = loc.hasOwnProperty('missing');
|
||||
const hasErrors = loc.hasOwnProperty('errors');
|
||||
return !hasMissing && !hasErrors;
|
||||
})
|
||||
.sort();
|
||||
|
||||
if (locales.join(',') !== availableLanguages.join(',')) {
|
||||
const missing = missingLocales(locales, availableLanguages);
|
||||
console.log('current 100%:', JSON.stringify(locales));
|
||||
console.log('package.json:', JSON.stringify(availableLanguages));
|
||||
console.log('missing prod:', JSON.stringify(missing));
|
||||
|
||||
if (process.argv.includes('--write')) {
|
||||
const pkgPath = require.resolve('../package.json');
|
||||
pkg.availableLanguages = locales;
|
||||
const str = JSON.stringify(pkg, null, 2) + '\n';
|
||||
console.log('Updating /package.json availableLanguages');
|
||||
fs.writeFileSync(pkgPath, str, 'utf-8');
|
||||
}
|
||||
} else {
|
||||
console.log('Production locales are up to date!');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue