44 lines
1.8 KiB
JavaScript
44 lines
1.8 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
const root = 'src';
|
|
const exts = ['.tsx', '.ts', '.jsx', '.js'];
|
|
const excludeDirs = ['locales', 'node_modules', 'i18n'];
|
|
const CJK = /[一-鿿]/;
|
|
function walk(dir) {
|
|
const out = [];
|
|
for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
const full = path.join(dir, e.name);
|
|
if (e.isDirectory()) { if (!excludeDirs.includes(e.name)) out.push(...walk(full)); }
|
|
else if (exts.includes(path.extname(e.name))) out.push(full);
|
|
}
|
|
return out;
|
|
}
|
|
const files = walk(root);
|
|
const result = [];
|
|
for (const f of files) {
|
|
const lines = fs.readFileSync(f, 'utf8').split('\n');
|
|
let userFacing = 0;
|
|
let totalCJK = 0;
|
|
for (const line of lines) {
|
|
const trimmed = line.trim();
|
|
// skip pure comments
|
|
if (trimmed.startsWith('//') || trimmed.startsWith('*') || trimmed.startsWith('/*')) continue;
|
|
// skip console.* lines
|
|
if (/console\./.test(line)) continue;
|
|
// skip lines that are only a comment after code (heuristic: contains // and no JSX/t() before)
|
|
if (CJK.test(line)) {
|
|
totalCJK++;
|
|
// user-facing heuristics: JSX text, string props, antd message, Option
|
|
const isCommentOnly = /\/\/.*[一-鿿]/.test(line) && !/(>|placeholder|title|label|content|message\.|notification\.|Modal\.|Tooltip|text=|children)/.test(line);
|
|
if (!isCommentOnly) userFacing++;
|
|
}
|
|
}
|
|
if (totalCJK > 0) result.push({ f: f.replace(root + '\\', ''), totalCJK, userFacing });
|
|
}
|
|
result.sort((a, b) => b.userFacing - a.userFacing);
|
|
console.log('Files with CJK:', result.length);
|
|
console.log('Total CJK lines (all):', result.reduce((s, r) => s + r.totalCJK, 0));
|
|
console.log('Estimated user-facing CJK lines:', result.reduce((s, r) => s + r.userFacing, 0));
|
|
console.log('\nPer-file (user-facing est):');
|
|
for (const r of result) console.log(String(r.userFacing).padStart(5), '\t', r.f);
|