Ajout de la commande /voyage et grosse MAJK de la commande /auberge
This commit is contained in:
81
tools/translate-ids.js
Normal file
81
tools/translate-ids.js
Normal file
@@ -0,0 +1,81 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
// Lire et parser le JSON
|
||||
const jsonPath = './compendium/wfrp4e-core.items.json';
|
||||
console.log('Lecture du fichier JSON...');
|
||||
const jsonData = JSON.parse(fs.readFileSync(jsonPath, 'utf8'));
|
||||
|
||||
// Créer le mapping id -> name
|
||||
const idToName = {};
|
||||
jsonData.entries.forEach(entry => {
|
||||
if (entry.id && entry.name) {
|
||||
idToName[entry.id] = entry.name;
|
||||
}
|
||||
});
|
||||
|
||||
console.log(`Nombre d'entrées trouvées: ${Object.keys(idToName).length}`);
|
||||
|
||||
// Fonction pour échapper les regex
|
||||
function escapeRegExp(string) {
|
||||
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||
}
|
||||
|
||||
// Parcourir tous les fichiers .js dans scripts/
|
||||
const scriptsDir = './scripts/';
|
||||
console.log('Analyse des fichiers dans', scriptsDir);
|
||||
const files = fs.readdirSync(scriptsDir).filter(f => f.endsWith('.js'));
|
||||
console.log(`${files.length} fichiers .js trouvés`);
|
||||
|
||||
let totalReplacements = 0;
|
||||
let filesModified = 0;
|
||||
const modifications = {};
|
||||
|
||||
files.forEach(file => {
|
||||
const filePath = path.join(scriptsDir, file);
|
||||
let content = fs.readFileSync(filePath, 'utf8');
|
||||
let originalContent = content;
|
||||
let fileReplacements = 0;
|
||||
|
||||
// Pour chaque ID, chercher et remplacer les occurrences entre guillemets
|
||||
Object.entries(idToName).forEach(([id, name]) => {
|
||||
// Chercher l'ID entre guillemets simples ou doubles
|
||||
const pattern1 = new RegExp('"' + escapeRegExp(id) + '"', 'g');
|
||||
const pattern2 = new RegExp("'" + escapeRegExp(id) + "'", 'g');
|
||||
|
||||
const matches1 = (content.match(pattern1) || []).length;
|
||||
const matches2 = (content.match(pattern2) || []).length;
|
||||
|
||||
if (matches1 > 0 || matches2 > 0) {
|
||||
content = content.replace(pattern1, '"' + name + '"');
|
||||
content = content.replace(pattern2, "'" + name + "'");
|
||||
|
||||
if (!modifications[file]) modifications[file] = [];
|
||||
modifications[file].push(` ${id} -> ${name} (${matches1 + matches2} fois)`);
|
||||
fileReplacements += matches1 + matches2;
|
||||
}
|
||||
});
|
||||
|
||||
if (content !== originalContent) {
|
||||
fs.writeFileSync(filePath, content, 'utf8');
|
||||
filesModified++;
|
||||
totalReplacements += fileReplacements;
|
||||
}
|
||||
});
|
||||
|
||||
console.log('\n===== RÉSULTAT =====');
|
||||
console.log(`Fichiers modifiés: ${filesModified} / ${files.length}`);
|
||||
console.log(`Total de remplacements: ${totalReplacements}`);
|
||||
|
||||
if (filesModified > 0) {
|
||||
console.log('\n===== DÉTAILS DES MODIFICATIONS =====');
|
||||
Object.entries(modifications).forEach(([file, changes]) => {
|
||||
console.log(`\n${file}:`);
|
||||
changes.slice(0, 10).forEach(change => console.log(change));
|
||||
if (changes.length > 10) {
|
||||
console.log(` ... et ${changes.length - 10} autres remplacements`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
console.log('\n✓ Traitement terminé !');
|
||||
Reference in New Issue
Block a user