@rokkit/icons 1.0.0-next.38 → 1.0.0-next.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/convert.js +26 -20
package/package.json
CHANGED
package/src/convert.js
CHANGED
|
@@ -9,11 +9,17 @@ import fs from 'fs'
|
|
|
9
9
|
|
|
10
10
|
export async function convert(folder, prefix, color = false) {
|
|
11
11
|
// Import icons
|
|
12
|
-
const iconSet = await importDirectory(folder, {
|
|
13
|
-
prefix
|
|
14
|
-
})
|
|
12
|
+
const iconSet = await importDirectory(folder, { prefix })
|
|
15
13
|
|
|
16
14
|
// Validate, clean up, fix palette and optimise
|
|
15
|
+
await processIcons(iconSet, color)
|
|
16
|
+
|
|
17
|
+
// Export
|
|
18
|
+
const collection = JSON.stringify(iconSet.export(), null, 2)
|
|
19
|
+
fs.writeFileSync(`./lib/${prefix}.json`, collection, 'utf8')
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function processIcons(iconSet, color) {
|
|
17
23
|
await iconSet.forEach(async (name, type) => {
|
|
18
24
|
if (type !== 'icon') {
|
|
19
25
|
return
|
|
@@ -28,20 +34,7 @@ export async function convert(folder, prefix, color = false) {
|
|
|
28
34
|
|
|
29
35
|
// Clean up and optimise icons
|
|
30
36
|
try {
|
|
31
|
-
|
|
32
|
-
await cleanupSVG(svg)
|
|
33
|
-
|
|
34
|
-
if (!color) {
|
|
35
|
-
await parseColors(svg, {
|
|
36
|
-
defaultColor: 'currentColor',
|
|
37
|
-
callback: (attr, colorStr, color) => {
|
|
38
|
-
return !color || isEmptyColor(color) ? colorStr : 'currentColor'
|
|
39
|
-
}
|
|
40
|
-
})
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Optimise
|
|
44
|
-
await runSVGO(svg)
|
|
37
|
+
await cleanAndOptimizeIcon(svg, color)
|
|
45
38
|
} catch (err) {
|
|
46
39
|
// Invalid icon
|
|
47
40
|
console.error(`Error parsing ${name}:`, err)
|
|
@@ -52,8 +45,21 @@ export async function convert(folder, prefix, color = false) {
|
|
|
52
45
|
// Update icon
|
|
53
46
|
iconSet.fromSVG(name, svg)
|
|
54
47
|
})
|
|
48
|
+
}
|
|
55
49
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
50
|
+
async function cleanAndOptimizeIcon(svg, color) {
|
|
51
|
+
// Clean up icon code
|
|
52
|
+
cleanupSVG(svg)
|
|
53
|
+
|
|
54
|
+
if (!color) {
|
|
55
|
+
await parseColors(svg, {
|
|
56
|
+
defaultColor: 'currentColor',
|
|
57
|
+
callback: (attr, colorStr, color) => {
|
|
58
|
+
return !color || isEmptyColor(color) ? colorStr : 'currentColor'
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Optimise
|
|
64
|
+
runSVGO(svg)
|
|
59
65
|
}
|