Initial commit
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const sharp = require('sharp'); // npm install sharp --save-dev
|
||||
|
||||
const faviconSvgPath = path.join(__dirname, 'favicon.svg');
|
||||
const appOutputDir = path.join(__dirname, '..', '..', 'app');
|
||||
|
||||
const faviconSizes = [16, 24, 32, 48, 64, 128, 256];
|
||||
|
||||
function ensureDirectoryExists(directory) {
|
||||
if (!fs.existsSync(directory)) {
|
||||
fs.mkdirSync(directory, { recursive: true });
|
||||
}
|
||||
}
|
||||
|
||||
async function generateFavicon() {
|
||||
try {
|
||||
ensureDirectoryExists(appOutputDir);
|
||||
|
||||
const tempPngs = [];
|
||||
for (const size of faviconSizes) {
|
||||
const pngPath = path.join(appOutputDir, `favicon-${size}.png`);
|
||||
await sharp(faviconSvgPath)
|
||||
.resize(size, size)
|
||||
.png()
|
||||
.toFile(pngPath);
|
||||
console.log(`SVG → PNG (${size}x${size}) ✅`);
|
||||
tempPngs.push(pngPath);
|
||||
}
|
||||
|
||||
await sharp(faviconSvgPath)
|
||||
.resize(256, 256)
|
||||
.toFile(path.join(appOutputDir, 'favicon.ico'));
|
||||
console.log('favicon.ico créé ✅');
|
||||
|
||||
for (const pngPath of tempPngs) {
|
||||
fs.unlinkSync(pngPath);
|
||||
}
|
||||
|
||||
console.log('Génération du favicon terminée !');
|
||||
} catch (err) {
|
||||
console.error('Erreur lors de la génération du favicon :', err);
|
||||
}
|
||||
}
|
||||
|
||||
generateFavicon();
|
||||
Reference in New Issue
Block a user