UNPKG

wttj-config

Version:

Front-end code lint and formatting config

39 lines (30 loc) 1.32 kB
import fs from 'fs' import { promisify } from 'util' import { exec } from 'child_process' // This file is meant to be used in the ci pipeline to check that // all the translations from the project are in sync with what has been // generated by the i18n:translate task // It slightly differs from what isTranslationTaskNeeded() which is used // in the pre-commit hook to check if the current commit adds new keys. // isTranslationTaskNeeded() does not check object equality const execute = promisify(exec) // get i18n config variables from package.json const { config } = JSON.parse(fs.readFileSync('package.json')) await execute('yarn i18n:extract') const hasEqualTempAndSourceLocales = () => { const tempTranslations = JSON.parse(fs.readFileSync(`${config.i18n.locales_dir_path}/temp.json`)) const sourceTranslations = JSON.parse( fs.readFileSync(`${config.i18n.locales_dir_path}/${config.i18n.default_language_filename}.json`) ) return JSON.stringify(tempTranslations) === JSON.stringify(sourceTranslations) } const isSynced = hasEqualTempAndSourceLocales() // remove temp.json file await execute(`rm -f ${config.i18n.locales_dir_path}/temp.json`) if (isSynced) { process.exit(0) } else { // eslint-disable-next-line no-console console.error('please run yarn i18n:translate') process.exit(1) }