const fs = require('fs'); const path = require('path'); const sharp = require('sharp'); // npm install sharp --save-dev const svgPath = path.join(__dirname, 'favicon.svg'); const pngPath = path.join(__dirname, 'favicon.png'); const appOutputDir = path.join(__dirname, '..', '..', 'app'); const faviconSizes = [16, 24, 32, 48, 64, 128, 256]; function detectSourceFile() { if (fs.existsSync(svgPath)) return { filePath: svgPath, type: 'svg' }; if (fs.existsSync(pngPath)) return { filePath: pngPath, type: 'png' }; throw new Error('Aucun fichier favicon.svg ou favicon.png trouvé dans dev/icons/'); } function ensureDirectoryExists(directory) { if (!fs.existsSync(directory)) { fs.mkdirSync(directory, { recursive: true }); } } async function generateFavicon() { try { const { filePath, type } = detectSourceFile(); console.log(`Source détectée : ${type.toUpperCase()} (${path.basename(filePath)})`); ensureDirectoryExists(appOutputDir); const tempPngs = []; for (const size of faviconSizes) { const outPath = path.join(appOutputDir, `favicon-${size}.png`); await sharp(filePath) .resize(size, size) .png() .toFile(outPath); console.log(`${type.toUpperCase()} → PNG (${size}x${size}) ✅`); tempPngs.push(outPath); } await sharp(filePath) .resize(256, 256) .toFile(path.join(appOutputDir, 'favicon.ico')); console.log('favicon.ico créé ✅'); for (const p of tempPngs) { fs.unlinkSync(p); } console.log('Génération du favicon terminée !'); } catch (err) { console.error('Erreur lors de la génération du favicon :', err); } } generateFavicon();