const fs = require('fs'); const path = require('path'); /** * Script pour mettre à jour version.json avec les informations de app_version.dart * Appelé automatiquement lors du build */ const versionFilePath = path.join(__dirname, '..', 'lib', 'config', 'app_version.dart'); const versionJsonPath = path.join(__dirname, '..', 'web', 'version.json'); const buildVersionJsonPath = path.join(__dirname, '..', 'build', 'web', 'version.json'); // Lire le fichier app_version.dart const versionContent = fs.readFileSync(versionFilePath, 'utf8'); // Extraire version const versionMatch = versionContent.match(/static const String version = '(\d+\.\d+\.\d+)';/); if (!versionMatch) { console.error('❌ Impossible de trouver la version dans app_version.dart'); process.exit(1); } const version = versionMatch[1]; console.log(`📦 Version trouvée: ${version}`); // Lire les notes de version si elles existent let releaseNotes = 'Mise à jour de l\'application'; const changelogPath = path.join(__dirname, '..', 'CHANGELOG.md'); if (fs.existsSync(changelogPath)) { const changelogContent = fs.readFileSync(changelogPath, 'utf8'); // Extraire la première section const firstSection = changelogContent.split('\n## ')[1]; if (firstSection) { const lines = firstSection.split('\n').slice(1, 6); // Prendre les 5 premières lignes releaseNotes = lines.join('\n').trim(); } } // Créer l'objet version const versionData = { version, updateUrl: 'https://app.em2events.fr', forceUpdate: true, // Mettre à true si mise à jour critique releaseNotes, timestamp: new Date().toISOString() }; // Écrire dans web/version.json fs.writeFileSync(versionJsonPath, JSON.stringify(versionData, null, 2)); console.log(`✅ web/version.json mis à jour`); // Copier aussi dans build/web/ si le dossier existe const buildWebDir = path.join(__dirname, '..', 'build', 'web'); if (fs.existsSync(buildWebDir)) { fs.writeFileSync(buildVersionJsonPath, JSON.stringify(versionData, null, 2)); console.log(`✅ build/web/version.json mis à jour`); } console.log('\n📝 Contenu du fichier version:'); console.log(JSON.stringify(versionData, null, 2));