gen-hunspell-filenames.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. const fs = require('node:fs');
  2. const path = require('node:path');
  3. const check = process.argv.includes('--check');
  4. const dictsPath = path.resolve(__dirname, '..', '..', 'third_party', 'hunspell_dictionaries');
  5. const gclientPath = 'third_party/hunspell_dictionaries';
  6. const allFiles = fs.readdirSync(dictsPath);
  7. const dictionaries = allFiles
  8. .filter(file => path.extname(file) === '.bdic');
  9. const licenses = allFiles
  10. .filter(file => file.startsWith('LICENSE') || file.startsWith('COPYING'));
  11. const content = `hunspell_dictionaries = [
  12. ${dictionaries.map(f => `"//${path.posix.join(gclientPath, f)}"`).join(',\n ')},
  13. ]
  14. hunspell_licenses = [
  15. ${licenses.map(f => `"//${path.posix.join(gclientPath, f)}"`).join(',\n ')},
  16. ]
  17. `;
  18. const filenamesPath = path.resolve(__dirname, '..', 'filenames.hunspell.gni');
  19. if (check) {
  20. const currentContent = fs.readFileSync(filenamesPath, 'utf8');
  21. if (currentContent !== content) {
  22. throw new Error('hunspell filenames need to be regenerated, latest generation does not match current file. Please run node gen-hunspell-filenames.js');
  23. }
  24. } else {
  25. fs.writeFileSync(filenamesPath, content);
  26. }