extract_cjk.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. const fs = require('fs');
  2. const path = require('path');
  3. const directories = ['d:/workspace/AuraK/web', 'd:/workspace/AuraK/server/src'];
  4. const excludeDirs = ['node_modules', '.git', 'dist', '.next', 'dist-check'];
  5. const extensions = ['.ts', '.tsx', '.js', '.jsx'];
  6. const cjkPattern = /[\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff]+/;
  7. const cjkLines = {};
  8. function walkSync(currentDirPath, callback) {
  9. fs.readdirSync(currentDirPath).forEach((name) => {
  10. const filePath = path.join(currentDirPath, name);
  11. const stat = fs.statSync(filePath);
  12. if (stat.isFile()) {
  13. callback(filePath, stat);
  14. } else if (stat.isDirectory() && !excludeDirs.includes(name)) {
  15. walkSync(filePath, callback);
  16. }
  17. });
  18. }
  19. directories.forEach(d => {
  20. walkSync(d, (filePath) => {
  21. if (extensions.some(ext => filePath.endsWith(ext))) {
  22. try {
  23. const content = fs.readFileSync(filePath, 'utf-8');
  24. const lines = content.split('\n');
  25. lines.forEach((line, i) => {
  26. if (cjkPattern.test(line)) {
  27. if (!cjkLines[filePath]) {
  28. cjkLines[filePath] = [];
  29. }
  30. cjkLines[filePath].push({ line: i + 1, text: line.trim() });
  31. }
  32. });
  33. } catch (e) {
  34. console.error(`Error reading ${filePath}: `, e);
  35. }
  36. }
  37. });
  38. });
  39. fs.writeFileSync('cjk_extract.json', JSON.stringify(cjkLines, null, 2), 'utf-8');
  40. console.log('Extracted to cjk_extract.json');