forked from timvisee/send
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate production locales using 'compare-locales'
- Loading branch information
Showing
2 changed files
with
53 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const { exec } = require('child_process'); | ||
const fs = require('fs'); | ||
|
||
const pkg = require('../package.json'); | ||
const availableLanguages = pkg.availableLanguages.sort(); | ||
|
||
const compareLocales = | ||
'compare-locales l10n.toml . `ls public/locales` --data=json'; | ||
|
||
exec(compareLocales, (err, stdout, stderr) => { | ||
if (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 missingLocales = missingLocales(locales, availableLanguages); | ||
console.log('current 100%:', JSON.stringify(locales)); | ||
console.log('package.json:', JSON.stringify(availableLanguages)); | ||
console.log('missing prod:', JSON.stringify(missingLocales)); | ||
|
||
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!'); | ||
} | ||
}); |