forked from public/foundryvtt-wh4-lang-fr-fr
158 lines
5.6 KiB
JavaScript
158 lines
5.6 KiB
JavaScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node: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 DATA_FILE = path.join(__dirname, 'script-comparison-data.json');
|
|
const LOG_FILE = path.join(__dirname, 'sync-scripts-log.txt');
|
|
|
|
// Charger les résultats de l'analyse
|
|
const data = JSON.parse(fs.readFileSync(DATA_FILE, 'utf-8'));
|
|
|
|
const log = [];
|
|
|
|
function writeLog(message) {
|
|
console.log(message);
|
|
log.push(message);
|
|
}
|
|
|
|
function deleteObsoleteScripts() {
|
|
writeLog('\n=== SUPPRESSION DES SCRIPTS OBSOLÈTES ===\n');
|
|
|
|
let deleted = 0;
|
|
data.usesLocalize.forEach(({file}) => {
|
|
const filePath = path.join(FR_SCRIPTS, file);
|
|
if (fs.existsSync(filePath)) {
|
|
fs.unlinkSync(filePath);
|
|
deleted++;
|
|
writeLog(`✓ Supprimé: ${file}`);
|
|
}
|
|
});
|
|
|
|
writeLog(`\nTotal supprimés: ${deleted}/${data.usesLocalize.length}`);
|
|
return deleted;
|
|
}
|
|
|
|
function copyNewScripts() {
|
|
writeLog('\n=== COPIE DES NOUVEAUX SCRIPTS ===\n');
|
|
|
|
let copied = 0;
|
|
data.onlyInWFRP4E.forEach(file => {
|
|
const sourcePath = path.join(WFRP4E_SCRIPTS, file);
|
|
const destPath = path.join(FR_SCRIPTS, file);
|
|
|
|
if (fs.existsSync(sourcePath)) {
|
|
fs.copyFileSync(sourcePath, destPath);
|
|
copied++;
|
|
writeLog(`✓ Copié: ${file}`);
|
|
} else {
|
|
writeLog(`✗ Source non trouvée: ${file}`);
|
|
}
|
|
});
|
|
|
|
writeLog(`\nTotal copiés: ${copied}/${data.onlyInWFRP4E.length}`);
|
|
return copied;
|
|
}
|
|
|
|
function deleteRemovedScripts() {
|
|
writeLog('\n=== SUPPRESSION DES SCRIPTS RETIRÉS ===\n');
|
|
|
|
let deleted = 0;
|
|
data.onlyInFR.forEach(file => {
|
|
const filePath = path.join(FR_SCRIPTS, file);
|
|
if (fs.existsSync(filePath)) {
|
|
fs.unlinkSync(filePath);
|
|
deleted++;
|
|
writeLog(`✓ Supprimé (n'existe plus dans WFRP4E): ${file}`);
|
|
}
|
|
});
|
|
|
|
writeLog(`\nTotal supprimés: ${deleted}/${data.onlyInFR.length}`);
|
|
return deleted;
|
|
}
|
|
|
|
function updateScripts() {
|
|
writeLog('\n=== MISE À JOUR DES SCRIPTS ===\n');
|
|
writeLog('Ces scripts ont été modifiés dans WFRP4E mais contiennent peut-être des traductions FR.');
|
|
writeLog('Ils nécessitent une révision manuelle.\n');
|
|
|
|
let updated = 0;
|
|
let needsReview = [];
|
|
|
|
data.needsUpdate.forEach(item => {
|
|
const wfrp4ePath = path.join(WFRP4E_SCRIPTS, item.file);
|
|
const frPath = path.join(FR_SCRIPTS, item.file);
|
|
|
|
const wfrp4eContent = fs.readFileSync(wfrp4ePath, 'utf-8');
|
|
const frContent = fs.readFileSync(frPath, 'utf-8');
|
|
|
|
// Vérifier si le script FR contient des textes en français
|
|
const hasFrenchText = /["'`](Chargement|Impossible|Voulez-vous|Êtes-vous|créé|modifié|supprimé)/i.test(frContent);
|
|
|
|
if (hasFrenchText) {
|
|
// Script avec traductions, nécessite révision manuelle
|
|
needsReview.push({
|
|
file: item.file,
|
|
reason: 'Contient des textes traduits en français'
|
|
});
|
|
writeLog(`⚠ RÉVISION NÉCESSAIRE: ${item.file} (contient des traductions)`);
|
|
} else {
|
|
// Pas de traductions détectées, on peut mettre à jour automatiquement
|
|
fs.copyFileSync(wfrp4ePath, frPath);
|
|
updated++;
|
|
writeLog(`✓ Mis à jour: ${item.file}`);
|
|
}
|
|
});
|
|
|
|
writeLog(`\nTotal mis à jour automatiquement: ${updated}`);
|
|
writeLog(`Total nécessitant révision: ${needsReview.length}`);
|
|
|
|
// Créer un fichier avec la liste des scripts à réviser
|
|
if (needsReview.length > 0) {
|
|
const reviewFile = path.join(__dirname, 'scripts-to-review.json');
|
|
fs.writeFileSync(reviewFile, JSON.stringify(needsReview, null, 2), 'utf-8');
|
|
writeLog(`\nListe des scripts à réviser sauvegardée dans: ${reviewFile}`);
|
|
}
|
|
|
|
return {updated, needsReview: needsReview.length};
|
|
}
|
|
|
|
// Programme principal
|
|
writeLog('='.repeat(60));
|
|
writeLog('SYNCHRONISATION DES SCRIPTS WFRP4E');
|
|
writeLog('='.repeat(60));
|
|
writeLog(`Date: ${new Date().toISOString()}\n`);
|
|
|
|
writeLog('Statistiques:');
|
|
writeLog(` - Scripts identiques: ${data.identical.length}`);
|
|
writeLog(` - Scripts obsolètes (localize): ${data.usesLocalize.length}`);
|
|
writeLog(` - Scripts à mettre à jour: ${data.needsUpdate.length}`);
|
|
writeLog(` - Nouveaux scripts (WFRP4E): ${data.onlyInWFRP4E.length}`);
|
|
writeLog(` - Scripts à supprimer (FR): ${data.onlyInFR.length}`);
|
|
|
|
// Demander confirmation
|
|
console.log('\nVoulez-vous continuer ? (appuyez sur Entrée pour continuer, Ctrl+C pour annuler)');
|
|
// Pour l'automatisation, on continue directement
|
|
// En production, on utiliserait readline pour une confirmation interactive
|
|
|
|
const obsoleteDeleted = deleteObsoleteScripts();
|
|
const removedDeleted = deleteRemovedScripts();
|
|
const newCopied = copyNewScripts();
|
|
const {updated, needsReview} = updateScripts();
|
|
|
|
writeLog('\n' + '='.repeat(60));
|
|
writeLog('RÉSUMÉ DES OPÉRATIONS');
|
|
writeLog('='.repeat(60));
|
|
writeLog(`Scripts obsolètes supprimés: ${obsoleteDeleted}`);
|
|
writeLog(`Scripts retirés supprimés: ${removedDeleted}`);
|
|
writeLog(`Nouveaux scripts copiés: ${newCopied}`);
|
|
writeLog(`Scripts mis à jour automatiquement: ${updated}`);
|
|
writeLog(`Scripts nécessitant révision manuelle: ${needsReview}`);
|
|
writeLog('='.repeat(60));
|
|
|
|
// Sauvegarder le log
|
|
fs.writeFileSync(LOG_FILE, log.join('\n'), 'utf-8');
|
|
writeLog(`\nLog sauvegardé dans: ${LOG_FILE}`);
|