extract_logs.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. const fs = require('fs');
  2. const path = require('path');
  3. function walkDir(dir, callback) {
  4. fs.readdirSync(dir).forEach(f => {
  5. let dirPath = path.join(dir, f);
  6. let isDirectory = fs.statSync(dirPath).isDirectory();
  7. if (isDirectory) {
  8. if (f !== 'node_modules' && f !== '.git' && f !== 'dist' && f !== '.next' && f !== 'build' && f !== 'coverage') {
  9. walkDir(dirPath, callback);
  10. }
  11. } else {
  12. if (dirPath.endsWith('.ts') || dirPath.endsWith('.tsx') || dirPath.endsWith('.js')) {
  13. callback(path.join(dir, f));
  14. }
  15. }
  16. });
  17. }
  18. const filesWithLogs = [];
  19. const logRegex = /(console|logger|Logger)\.(log|error|warn|info|debug|verbose)\(([^)]*[\u4e00-\u9fa5]+[^)]*)\)/g;
  20. walkDir('d:/workspace/AuraK/server', (filePath) => {
  21. const content = fs.readFileSync(filePath, 'utf8');
  22. if (logRegex.test(content)) {
  23. filesWithLogs.push(filePath);
  24. }
  25. });
  26. walkDir('d:/workspace/AuraK/web', (filePath) => {
  27. const content = fs.readFileSync(filePath, 'utf8');
  28. if (logRegex.test(content)) {
  29. filesWithLogs.push(filePath);
  30. }
  31. });
  32. console.log('Found ' + filesWithLogs.length + ' files');
  33. fs.writeFileSync('d:/workspace/AuraK/files_to_translate.json', JSON.stringify(filesWithLogs, null, 2));