checkCoverage.js 975 B

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