Files
lcbp3/fix-console.cjs
admin 11984bfa29
CI Pipeline / build (push) Failing after 12m41s
Build and Deploy / deploy (push) Failing after 2m44s
260322:1648 Correct Coresspondence / Doing RFA / Correct CI
2026-03-22 16:48:12 +07:00

47 lines
1.1 KiB
JavaScript

const fs = require('fs');
const path = require('path');
const rootDir = process.cwd();
function walk(dir) {
let results = [];
const list = fs.readdirSync(dir);
list.forEach((file) => {
file = path.join(dir, file);
const stat = fs.statSync(file);
if (
stat &&
stat.isDirectory() &&
!file.includes('node_modules') &&
!file.includes('.next') &&
!file.includes('dist')
) {
results = results.concat(walk(file));
} else if (file.endsWith('.ts') || file.endsWith('.tsx')) {
results.push(file);
}
});
return results;
}
const files = walk(rootDir);
files.forEach((file) => {
let content = fs.readFileSync(file, 'utf8');
let changed = false;
// Fix no-console in frontend specifically (as per ADR-011)
if (file.includes('frontend')) {
const consoleRegex = /console\.(log|error|warn|info|debug)\(.*\);?/g;
if (consoleRegex.test(content)) {
content = content.replace(consoleRegex, (match) => `// ${match} /* TODO: Remove before prod */`);
changed = true;
}
}
if (changed) {
fs.writeFileSync(file, content, 'utf8');
console.log(`Updated ${file}`);
}
});