1 changed files with 104 additions and 0 deletions
@ -0,0 +1,104 @@ |
|||
/* eslint-disable no-console */ |
|||
|
|||
const { spawn } = require('child_process') |
|||
|
|||
// those wordings are dynamically created, so they are detected
|
|||
// as false positive
|
|||
const WHITELIST = [ |
|||
'app:operation.type.IN', |
|||
'app:operation.type.OUT', |
|||
'app:exchange.coinhouse', |
|||
'app:exchange.changelly', |
|||
'app:exchange.coinmama', |
|||
'app:exchange.simplex', |
|||
'app:exchange.paybis', |
|||
'app:addAccounts.accountToImportSubtitle_plural', |
|||
'app:dashboard.summary_plural', |
|||
'app:addAccounts.success_plural', |
|||
'app:addAccounts.successDescription_plural', |
|||
'app:time.since.day', |
|||
'app:time.since.week', |
|||
'app:time.since.month', |
|||
'app:time.since.year', |
|||
'app:time.day', |
|||
'app:time.week', |
|||
'app:time.month', |
|||
'app:time.year', |
|||
'app:addAccounts.cta.add_plural', |
|||
'app:manager.apps.installing', |
|||
'app:manager.apps.uninstalling', |
|||
'app:manager.apps.installSuccess', |
|||
'app:manager.apps.uninstallSuccess', |
|||
] |
|||
|
|||
const WORDINGS = { |
|||
app: require('../static/i18n/en/app.json'), |
|||
onboarding: require('../static/i18n/en/onboarding.json'), |
|||
// errors: require('../static/i18n/en/errors.json'),
|
|||
// language: require('../static/i18n/en/language.json'),
|
|||
} |
|||
|
|||
async function main() { |
|||
for (const ns in WORDINGS) { |
|||
if (WORDINGS.hasOwnProperty(ns)) { |
|||
try { |
|||
await cleanNamespace(ns) |
|||
} catch (err) { |
|||
console.log(err) |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
async function cleanNamespace(ns) { |
|||
const root = WORDINGS[ns] |
|||
await checkForUsage(root, ns, ':') |
|||
} |
|||
|
|||
async function checkForUsage(v, key, delimiter = '.') { |
|||
if (WHITELIST.includes(key)) { |
|||
return |
|||
} |
|||
if (typeof v === 'object') { |
|||
for (const k in v) { |
|||
if (v.hasOwnProperty(k)) { |
|||
await checkForUsage(v[k], `${key}${delimiter}${k}`) |
|||
} |
|||
} |
|||
} else if (typeof v === 'string') { |
|||
try { |
|||
const hasOccurences = await getHasOccurrences(key) |
|||
if (!hasOccurences) { |
|||
console.log(key) |
|||
} |
|||
} catch (err) { |
|||
console.log(err) |
|||
} |
|||
} else { |
|||
throw new Error('invalid input') |
|||
} |
|||
} |
|||
|
|||
function getHasOccurrences(key) { |
|||
return new Promise(resolve => { |
|||
const childProcess = spawn('rg', [key, 'src']) |
|||
let data |
|||
childProcess.stdout.on('data', d => { |
|||
data = d.toString() |
|||
}) |
|||
childProcess.on('close', () => { |
|||
if (!data) return resolve(false) |
|||
const rows = data.split('\n').filter(Boolean) |
|||
return resolve(rows.length > 0) |
|||
}) |
|||
childProcess.on('error', err => { |
|||
if (err.code === 'ENOENT') { |
|||
console.log(`You need to install ripgrep first`) |
|||
console.log(`see: https://github.com/BurntSushi/ripgrep`) |
|||
process.exit(1) |
|||
} |
|||
}) |
|||
}) |
|||
} |
|||
|
|||
main() |
Loading…
Reference in new issue