197 lines
7.0 KiB
JavaScript
197 lines
7.0 KiB
JavaScript
import fs from 'fs';
|
|
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
|
const WFRP4E_SCRIPTS = '/home/morr/work/foundryvtt/WFRP4e-FoundryVTT/scripts';
|
|
const FR_SCRIPTS = '/home/morr/work/foundryvtt/foundryvtt-wh4-lang-fr-fr/scripts';
|
|
const REPORT_FILE = '/home/morr/work/foundryvtt/foundryvtt-wh4-lang-fr-fr/tools/script-comparison-report.md';
|
|
|
|
// Recherche des patterns qui indiquent du texte localisé
|
|
const LOCALIZE_PATTERNS = [
|
|
/game\.i18n\.localize\(/g,
|
|
/game\.i18n\.format\(/g,
|
|
/game\.wfrp4e\.i18n\./g
|
|
];
|
|
|
|
// Patterns de textes en dur qui ont probablement été traduits
|
|
const HARDCODED_TEXT_PATTERNS = [
|
|
/ui\.notifications\.(info|warn|error|notify)\s*\(\s*["'`]([^"'`]+)["'`]/g,
|
|
/this\.script\.(scriptNotification|scriptMessage|notification)\s*\(\s*["'`]([^"'`]+)["'`]/g
|
|
];
|
|
|
|
function analyzeScript(filePath) {
|
|
const content = fs.readFileSync(filePath, 'utf-8');
|
|
|
|
// Vérifie si le fichier utilise localize()
|
|
const hasLocalize = LOCALIZE_PATTERNS.some(pattern => pattern.test(content));
|
|
|
|
// Extrait les textes en dur
|
|
const hardcodedTexts = [];
|
|
HARDCODED_TEXT_PATTERNS.forEach(pattern => {
|
|
const matches = content.matchAll(pattern);
|
|
for (const match of matches) {
|
|
hardcodedTexts.push(match[2] || match[1]);
|
|
}
|
|
});
|
|
|
|
return {
|
|
hasLocalize,
|
|
hardcodedTexts,
|
|
content,
|
|
size: content.length
|
|
};
|
|
}
|
|
|
|
function compareScripts() {
|
|
const wfrp4eFiles = fs.readdirSync(WFRP4E_SCRIPTS).filter(f => f.endsWith('.js'));
|
|
const frFiles = fs.readdirSync(FR_SCRIPTS).filter(f => f.endsWith('.js'));
|
|
|
|
const results = {
|
|
identical: [],
|
|
needsUpdate: [],
|
|
usesLocalize: [],
|
|
onlyInFR: [],
|
|
onlyInWFRP4E: [],
|
|
total: 0
|
|
};
|
|
|
|
// Fichiers présents seulement dans le module FR
|
|
frFiles.forEach(file => {
|
|
if (!wfrp4eFiles.includes(file)) {
|
|
results.onlyInFR.push(file);
|
|
}
|
|
});
|
|
|
|
// Fichiers présents seulement dans WFRP4E
|
|
wfrp4eFiles.forEach(file => {
|
|
if (!frFiles.includes(file)) {
|
|
results.onlyInWFRP4E.push(file);
|
|
}
|
|
});
|
|
|
|
// Comparaison des fichiers communs
|
|
const commonFiles = wfrp4eFiles.filter(f => frFiles.includes(f));
|
|
results.total = commonFiles.length;
|
|
|
|
commonFiles.forEach(file => {
|
|
const wfrp4ePath = path.join(WFRP4E_SCRIPTS, file);
|
|
const frPath = path.join(FR_SCRIPTS, file);
|
|
|
|
const wfrp4e = analyzeScript(wfrp4ePath);
|
|
const fr = analyzeScript(frPath);
|
|
|
|
// Si WFRP4E utilise localize(), le script FR n'est plus nécessaire
|
|
if (wfrp4e.hasLocalize) {
|
|
results.usesLocalize.push({
|
|
file,
|
|
details: 'Le système utilise maintenant localize() - script FR obsolète'
|
|
});
|
|
}
|
|
// Si les contenus sont identiques
|
|
else if (wfrp4e.content === fr.content) {
|
|
results.identical.push(file);
|
|
}
|
|
// Si différents, besoin de mise à jour
|
|
else {
|
|
results.needsUpdate.push({
|
|
file,
|
|
wfrp4eSize: wfrp4e.size,
|
|
frSize: fr.size,
|
|
wfrp4eTexts: wfrp4e.hardcodedTexts,
|
|
frTexts: fr.hardcodedTexts
|
|
});
|
|
}
|
|
});
|
|
|
|
return results;
|
|
}
|
|
|
|
function generateReport(results) {
|
|
let report = `# Rapport de comparaison des scripts\n\n`;
|
|
report += `Date: ${new Date().toISOString()}\n\n`;
|
|
report += `## Résumé\n\n`;
|
|
report += `- **Total de fichiers communs**: ${results.total}\n`;
|
|
report += `- **Scripts identiques**: ${results.identical.length}\n`;
|
|
report += `- **Scripts nécessitant mise à jour**: ${results.needsUpdate.length}\n`;
|
|
report += `- **Scripts utilisant localize() (obsolètes)**: ${results.usesLocalize.length}\n`;
|
|
report += `- **Scripts uniquement dans FR**: ${results.onlyInFR.length}\n`;
|
|
report += `- **Scripts uniquement dans WFRP4E**: ${results.onlyInWFRP4E.length}\n\n`;
|
|
|
|
if (results.usesLocalize.length > 0) {
|
|
report += `## Scripts obsolètes (utilisant localize() dans WFRP4E)\n\n`;
|
|
report += `Ces scripts peuvent être supprimés du module FR car le système utilise maintenant les fichiers de localisation.\n\n`;
|
|
results.usesLocalize.forEach(({file, details}) => {
|
|
report += `- \`${file}\` - ${details}\n`;
|
|
});
|
|
report += `\n`;
|
|
}
|
|
|
|
if (results.needsUpdate.length > 0) {
|
|
report += `## Scripts nécessitant une mise à jour\n\n`;
|
|
results.needsUpdate.slice(0, 50).forEach(item => {
|
|
report += `### ${item.file}\n\n`;
|
|
report += `- Taille WFRP4E: ${item.wfrp4eSize} octets\n`;
|
|
report += `- Taille FR: ${item.frSize} octets\n`;
|
|
if (item.wfrp4eTexts.length > 0) {
|
|
report += `- Textes WFRP4E: ${item.wfrp4eTexts.join(', ')}\n`;
|
|
}
|
|
if (item.frTexts.length > 0) {
|
|
report += `- Textes FR: ${item.frTexts.join(', ')}\n`;
|
|
}
|
|
report += `\n`;
|
|
});
|
|
if (results.needsUpdate.length > 50) {
|
|
report += `\n... et ${results.needsUpdate.length - 50} autres fichiers\n\n`;
|
|
}
|
|
}
|
|
|
|
if (results.onlyInWFRP4E.length > 0) {
|
|
report += `## Scripts uniquement dans WFRP4E (${results.onlyInWFRP4E.length})\n\n`;
|
|
report += `Ces scripts existent dans WFRP4E mais pas dans le module FR.\n\n`;
|
|
results.onlyInWFRP4E.slice(0, 20).forEach(file => {
|
|
report += `- ${file}\n`;
|
|
});
|
|
if (results.onlyInWFRP4E.length > 20) {
|
|
report += `\n... et ${results.onlyInWFRP4E.length - 20} autres\n`;
|
|
}
|
|
report += `\n`;
|
|
}
|
|
|
|
if (results.onlyInFR.length > 0) {
|
|
report += `## Scripts uniquement dans FR (${results.onlyInFR.length})\n\n`;
|
|
report += `Ces scripts existent dans le module FR mais plus dans WFRP4E (probablement supprimés).\n\n`;
|
|
results.onlyInFR.slice(0, 20).forEach(file => {
|
|
report += `- ${file}\n`;
|
|
});
|
|
if (results.onlyInFR.length > 20) {
|
|
report += `\n... et ${results.onlyInFR.length - 20} autres\n`;
|
|
}
|
|
report += `\n`;
|
|
}
|
|
|
|
return report;
|
|
}
|
|
|
|
console.log('Analyse des scripts en cours...');
|
|
const results = compareScripts();
|
|
const report = generateReport(results);
|
|
|
|
fs.writeFileSync(REPORT_FILE, report, 'utf-8');
|
|
|
|
console.log(`\nRapport généré: ${REPORT_FILE}`);
|
|
console.log(`\nRésumé:`);
|
|
console.log(` Identiques: ${results.identical.length}`);
|
|
console.log(` À mettre à jour: ${results.needsUpdate.length}`);
|
|
console.log(` Obsolètes (localize): ${results.usesLocalize.length}`);
|
|
console.log(` Uniquement FR: ${results.onlyInFR.length}`);
|
|
console.log(` Uniquement WFRP4E: ${results.onlyInWFRP4E.length}`);
|
|
|
|
// Export des résultats pour utilisation ultérieure
|
|
fs.writeFileSync(
|
|
path.join(path.dirname(REPORT_FILE), 'script-comparison-data.json'),
|
|
JSON.stringify(results, null, 2),
|
|
'utf-8'
|
|
);
|