extract_keys.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. const fs = require('fs');
  2. const path = require('path');
  3. function getFiles(dir, fileList = []) {
  4. const files = fs.readdirSync(dir);
  5. for (const file of files) {
  6. const name = path.join(dir, file);
  7. if (fs.statSync(name).isDirectory()) {
  8. if (file !== 'node_modules' && file !== '.git' && file !== 'dist') {
  9. getFiles(name, fileList);
  10. }
  11. } else {
  12. if (name.endsWith('.tsx') || name.endsWith('.ts')) {
  13. fileList.push(name);
  14. }
  15. }
  16. }
  17. return fileList;
  18. }
  19. const webDir = path.join('d:', 'workspace', 'AuraK', 'web');
  20. const files = getFiles(webDir);
  21. const keys = new Set();
  22. const tRegex = /t\(\s*['"]([a-zA-Z0-9_-]+)['"]/g;
  23. for (const file of files) {
  24. const content = fs.readFileSync(file, 'utf8');
  25. let match;
  26. while ((match = tRegex.exec(content)) !== null) {
  27. keys.add(match[1]);
  28. }
  29. }
  30. const sortedKeys = Array.from(keys).sort();
  31. fs.writeFileSync(path.join('d:', 'workspace', 'AuraK', 'all_used_keys.txt'), sortedKeys.join('\n'));
  32. console.log(`Extracted ${sortedKeys.length} unique keys to all_used_keys.txt`);