-
Notifications
You must be signed in to change notification settings - Fork 2
/
.iconifyrc.js
65 lines (55 loc) · 1.49 KB
/
.iconifyrc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const {
cleanupSVG,
importDirectory,
isEmptyColor,
parseColors,
runSVGO,
} = require('@iconify/tools');
const path = require('path');
const fs = require('fs').promises;
const svgPath = path.join(__dirname, 'icons');
const savePath = path.join(__dirname, './src/components/icon', 'local.json');
(async () => {
// Import icons
const iconSet = await importDirectory(svgPath, {
prefix: 'local',
});
// Validate, clean up, fix palette and optimise
iconSet.forEach((name, type) => {
if (type !== 'icon') {
return;
}
const svg = iconSet.toSVG(name);
if (!svg) {
// Invalid icon
iconSet.remove(name);
return;
}
// Clean up and optimise icons
try {
// Clean up icon code
cleanupSVG(svg);
// Assume icon is monotone: replace color with currentColor, add if missing
// If icon is not monotone, remove this code
parseColors(svg, {
defaultColor: 'currentColor',
callback: (attr, colorStr, color) => {
return !color || isEmptyColor(color) ? colorStr : 'currentColor';
},
});
// Optimise
runSVGO(svg);
} catch (err) {
// Invalid icon
console.error(`Error parsing ${name}:`, err);
iconSet.remove(name);
return;
}
// Update icon
iconSet.fromSVG(name, svg);
});
// Export as IconifyJSON
const exported = JSON.stringify(iconSet.export(), null, '\t') + '\n';
// Save to file
await fs.writeFile(savePath, exported, 'utf8');
})();