forked from public/foundryvtt-wh4-lang-fr-fr
93 lines
2.5 KiB
JavaScript
93 lines
2.5 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
// Patterns pour détecter les variables JavaScript nommées "Tests"
|
|
const patterns = [
|
|
// Déclarations de variables
|
|
/\b(let|const|var)\s+Tests\b/g,
|
|
// Paramètres de fonction
|
|
/function\s+\w*\s*\([^)]*\bTests\b[^)]*\)/g,
|
|
// Arrow functions avec paramètres
|
|
/\(\s*[^)]*\bTests\b[^)]*\)\s*=>/g,
|
|
// Arrow function avec un seul paramètre sans parenthèses
|
|
/\bTests\s*=>/g,
|
|
// Destructuration d'objets
|
|
/\{\s*[^}]*\bTests\b[^}]*\}\s*=/g,
|
|
// Destructuration de tableaux
|
|
/\[\s*[^\]]*\bTests\b[^\]]*\]\s*=/g,
|
|
// Catch clause
|
|
/catch\s*\(\s*Tests\s*\)/g,
|
|
// For...of/in loops
|
|
/for\s*\(\s*(let|const|var)?\s*Tests\s+(of|in)\b/g,
|
|
];
|
|
|
|
function findTestsInFile(filePath) {
|
|
const content = fs.readFileSync(filePath, 'utf-8');
|
|
const lines = content.split('\n');
|
|
const results = [];
|
|
|
|
lines.forEach((line, index) => {
|
|
patterns.forEach(pattern => {
|
|
pattern.lastIndex = 0; // Reset regex
|
|
if (pattern.test(line)) {
|
|
results.push({
|
|
line: index + 1,
|
|
content: line.trim()
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
return results;
|
|
}
|
|
|
|
function walkDirectory(dir) {
|
|
const files = fs.readdirSync(dir);
|
|
const allResults = {};
|
|
|
|
files.forEach(file => {
|
|
const filePath = path.join(dir, file);
|
|
const stat = fs.statSync(filePath);
|
|
|
|
if (stat.isDirectory()) {
|
|
Object.assign(allResults, walkDirectory(filePath));
|
|
} else if (file.endsWith('.js')) {
|
|
const results = findTestsInFile(filePath);
|
|
if (results.length > 0) {
|
|
allResults[filePath] = results;
|
|
}
|
|
}
|
|
});
|
|
|
|
return allResults;
|
|
}
|
|
|
|
// Main
|
|
const scriptsDir = path.join(__dirname, 'scripts');
|
|
|
|
console.log('🔍 Recherche des variables JavaScript nommées "Tests" dans le répertoire scripts/...\n');
|
|
|
|
if (!fs.existsSync(scriptsDir)) {
|
|
console.error('❌ Le répertoire scripts/ n\'existe pas');
|
|
process.exit(1);
|
|
}
|
|
|
|
const results = walkDirectory(scriptsDir);
|
|
|
|
if (Object.keys(results).length === 0) {
|
|
console.log('✅ Aucune variable JavaScript nommée "Tests" trouvée.');
|
|
} else {
|
|
console.log(`⚠️ ${Object.keys(results).length} fichier(s) contenant des variables "Tests" :\n`);
|
|
|
|
Object.entries(results).forEach(([filePath, occurrences]) => {
|
|
const relativePath = path.relative(__dirname, filePath);
|
|
console.log(`📄 ${relativePath}`);
|
|
occurrences.forEach(({ line, content }) => {
|
|
console.log(` Ligne ${line}: ${content}`);
|
|
});
|
|
console.log('');
|
|
});
|
|
}
|