Class_generator/migrate-console.js
StillHammer 1f8688c4aa Fix WebSocket logging system and add comprehensive network features
- Fix WebSocket server to properly broadcast logs to all connected clients
- Integrate professional logging system with real-time WebSocket interface
- Add network status indicator with DigitalOcean Spaces connectivity
- Implement AWS Signature V4 authentication for private bucket access
- Add JSON content loader with backward compatibility to JS modules
- Restore navigation breadcrumb system with comprehensive logging
- Add multiple content formats: JSON + JS with automatic discovery
- Enhance top bar with logger toggle and network status indicator
- Remove deprecated temp-games module and clean up unused files

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-15 23:05:14 +08:00

114 lines
3.3 KiB
JavaScript

#!/usr/bin/env node
// Script de migration des console.log vers logSh
const fs = require('fs');
const path = require('path');
// Fonction pour parcourir récursivement les fichiers
function walkSync(dir, filelist = []) {
const files = fs.readdirSync(dir);
files.forEach(file => {
const filepath = path.join(dir, file);
const stat = fs.statSync(filepath);
if (stat.isDirectory()) {
// Skip certains dossiers
if (!['node_modules', '.git', 'export_logger'].includes(file)) {
filelist = walkSync(filepath, filelist);
}
} else if (file.endsWith('.js') && !file.startsWith('migrate-')) {
filelist.push(filepath);
}
});
return filelist;
}
// Fonction pour migrer un fichier
function migrateFile(filepath) {
console.log(`🔄 Migration: ${filepath}`);
let content = fs.readFileSync(filepath, 'utf8');
let modified = false;
// Remplacements avec mapping vers logSh
const replacements = [
// console.log -> logSh avec niveau INFO
{
pattern: /console\.log\((.*?)\);?/g,
replacement: (match, args) => {
// Si c'est déjà un template string avec des variables, le garder tel quel
if (args.includes('`') || args.includes('${')) {
return `logSh(${args}, 'INFO');`;
}
// Sinon, traiter normalement
return `logSh(${args}, 'INFO');`;
}
},
// console.warn -> logSh avec niveau WARN
{
pattern: /console\.warn\((.*?)\);?/g,
replacement: (match, args) => {
return `logSh(${args}, 'WARN');`;
}
},
// console.error -> logSh avec niveau ERROR
{
pattern: /console\.error\((.*?)\);?/g,
replacement: (match, args) => {
return `logSh(${args}, 'ERROR');`;
}
}
];
// Appliquer les remplacements
replacements.forEach(({ pattern, replacement }) => {
const originalContent = content;
content = content.replace(pattern, replacement);
if (content !== originalContent) {
modified = true;
}
});
// Sauvegarder si modifié
if (modified) {
fs.writeFileSync(filepath, content, 'utf8');
console.log(`✅ Migré: ${filepath}`);
return true;
} else {
console.log(`⏸️ Pas de changement: ${filepath}`);
return false;
}
}
// Script principal
function main() {
console.log('🚀 Démarrage migration console vers logSh...');
const projectRoot = __dirname;
const jsFiles = walkSync(projectRoot);
console.log(`📁 Trouvé ${jsFiles.length} fichiers JavaScript`);
let migratedCount = 0;
jsFiles.forEach(filepath => {
if (migrateFile(filepath)) {
migratedCount++;
}
});
console.log(`\n🎉 Migration terminée!`);
console.log(`📊 ${migratedCount} fichiers modifiés sur ${jsFiles.length}`);
console.log(`\n🔍 Pour vérifier, lance:`);
console.log(`grep -r "console\\." --include="*.js" . || echo "✅ Plus de console dans le code!"`);
}
// Lancer le script
if (require.main === module) {
main();
}
module.exports = { migrateFile, walkSync };