checkCoverage.js 817 B

1234567891011121314151617181920212223242526272829303132333435
  1. const fs = require('fs')
  2. const Path = require('path')
  3. const LOCALES = Path.join(__dirname, '../../locales')
  4. const SORT_BY_PROGRESS = process.argv.includes('--sort-by-progress')
  5. function count(file) {
  6. return Object.keys(require(Path.join(LOCALES, file))).length
  7. }
  8. async function main() {
  9. const EN = count('en.json')
  10. const rows = []
  11. for (const file of await fs.promises.readdir(LOCALES)) {
  12. if (file === 'README.md') continue
  13. const n = count(file)
  14. const name = file.replace('.json', '')
  15. rows.push({
  16. name,
  17. done: n,
  18. missing: EN - n,
  19. progress: ((100 * n) / EN).toFixed(2).padStart(5, ' ') + '%',
  20. })
  21. }
  22. if (SORT_BY_PROGRESS) {
  23. rows.sort((a, b) => b.done - a.done)
  24. }
  25. console.table(rows)
  26. }
  27. main().catch(error => {
  28. console.error(error)
  29. process.exit(1)
  30. })