59a33380df
Add PNG source file detection in `make-favicon.js` so the script can use either `favicon.svg` or `favicon.png` as input. Previously, only SVG was supported, causing failures when no SVG was present. - Introduce `detectSourceFile()` to check for SVG first, then PNG - Rename variables to avoid shadowing (`pngPath` → `outPath`, loop var) - Log detected source type for better visibility during generation - Update generated `favicon.ico` accordingly
57 lines
1.7 KiB
JavaScript
57 lines
1.7 KiB
JavaScript
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();
|