(
files: string[],
{sourceLocale, missingKeys, extraKeys, structuralEquality}: VerifyOpts
)
| 18 | } |
| 19 | |
| 20 | export async function verify( |
| 21 | files: string[], |
| 22 | {sourceLocale, missingKeys, extraKeys, structuralEquality}: VerifyOpts |
| 23 | ): Promise<void> { |
| 24 | debug('Checking translation files:') |
| 25 | files.forEach(fn => debug(fn)) |
| 26 | |
| 27 | const translationFilesContents = ( |
| 28 | await Promise.all( |
| 29 | files.map(async fn => [basename(fn, '.json'), await readJSON(fn)]) |
| 30 | ) |
| 31 | ).reduce<Record<string, object>>((all, [locale, content]) => { |
| 32 | all[locale] = content |
| 33 | return all |
| 34 | }, {}) |
| 35 | debug('Verifying files:', files) |
| 36 | |
| 37 | let exitCode = 0 |
| 38 | |
| 39 | if ( |
| 40 | missingKeys && |
| 41 | !(await checkMissingKeys(translationFilesContents, sourceLocale)) |
| 42 | ) { |
| 43 | exitCode = 1 |
| 44 | } |
| 45 | |
| 46 | if ( |
| 47 | extraKeys && |
| 48 | !(await checkExtraKeys(translationFilesContents, sourceLocale)) |
| 49 | ) { |
| 50 | exitCode = 1 |
| 51 | } |
| 52 | |
| 53 | if ( |
| 54 | structuralEquality && |
| 55 | !(await checkStructuralEquality(translationFilesContents, sourceLocale)) |
| 56 | ) { |
| 57 | exitCode = 1 |
| 58 | } |
| 59 | |
| 60 | process.exit(exitCode) |
| 61 | } |
no test coverage detected