46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
function toEssentialIcon(icon = {}) {
|
|
const name = typeof icon.name === 'string' ? icon.name : '';
|
|
const prefix = typeof icon.prefix === 'string' ? icon.prefix : '';
|
|
|
|
if (!name || !prefix) return null;
|
|
|
|
const minimal = { name, prefix };
|
|
if (typeof icon.tags === 'string' && icon.tags.trim()) {
|
|
minimal.tags = icon.tags;
|
|
}
|
|
|
|
return minimal;
|
|
}
|
|
|
|
function buildIconsJs({
|
|
inputPath = path.join(__dirname, 'data', 'all_icons.json'),
|
|
outputPath = path.join(__dirname, 'data', 'all_icons.js')
|
|
} = {}) {
|
|
if (!fs.existsSync(inputPath)) {
|
|
throw new Error(`Missing ${inputPath}`);
|
|
}
|
|
|
|
const raw = fs.readFileSync(inputPath, 'utf8');
|
|
const icons = JSON.parse(raw).map(toEssentialIcon).filter(Boolean);
|
|
|
|
const payload = `window.FICONS_DATA = ${JSON.stringify(icons)};\n`;
|
|
fs.writeFileSync(outputPath, payload, 'utf8');
|
|
|
|
const sizeMb = (payload.length / (1024 * 1024)).toFixed(1);
|
|
console.log(`Wrote ${outputPath} (${sizeMb} MB)`);
|
|
}
|
|
|
|
if (require.main === module) {
|
|
try {
|
|
buildIconsJs();
|
|
} catch (error) {
|
|
console.error(error.message || error);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
module.exports = buildIconsJs;
|