-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
199 lines (154 loc) · 5.59 KB
/
test.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
const path = require('path');
const EC = require('eight-colors');
const CG = require('console-grid');
const svgMinifier = require('../lib');
const tiktokHandler = ($svg, item, $) => {
// only for tiktok
if (item.name === 'tiktok') {
// console.log($.html());
// console.log('DTD==============================');
// directive
const directive = $.root()[0].children.find((c) => c.type === 'directive');
if (directive) {
console.log(directive.data);
const d = directive.data.split('"')[1];
EC.logYellow(`tiktok replacement: ${d}`);
$.root().find('[d="&z;"]').attr('d', d);
}
// console.log('==================================');
// console.log($.html());
}
};
const tests = {
'my-icons': {
dirs: [path.resolve(__dirname, 'icons/my-icons')],
onSVGName: function(name, item) {
// filter
// if (name === 'at') {
// return;
// }
return name;
},
onSVGContent: function(content, item) {
if (item.name === 'content') {
// console.log(item);
return content.split('{placeholder}').join('content');
}
content = content.split('fill:#000000').join('fill:currentColor');
content = content.split('fill="#000"').join('fill="currentColor"');
return content;
},
onSVGDocument: function($svg, item, $) {
// const fill = $svg.attr('fill');
// if (!fill) {
// $svg.attr('fill', 'currentColor');
// }
if (['ada', 'augeas'].includes(item.name)) {
$svg.attr('viewBox', '0 0 512 512');
$svg.attr('fill', 'currentColor');
return;
}
tiktokHandler($svg, item, $);
},
onSVGOptimized: function($svg, item, $) {
// // filter
if (item.name === 'at') {
EC.logYellow('at.svg filtered');
return false;
}
if (['ada', 'augeas'].includes(item.name)) {
['g', 'path'].forEach((tag) => {
$svg.find(tag).each((i, it) => {
const $elem = $(it);
const fill = $elem.attr('fill');
if (fill && fill !== 'none') {
$elem.attr('fill', 'currentColor');
}
const stroke = $elem.attr('stroke');
if (stroke && stroke !== 'none') {
$elem.attr('stroke', 'currentColor');
}
});
});
}
},
onFinish: function(options, metadata) {
console.log('====================================================');
console.log(`onFinish: ${metadata.id}`);
EC.logYellow('duplicateNames');
console.log(options.duplicateNames);
EC.logYellow('duplicateContents');
console.log(options.duplicateContents);
},
metadata: {
name: 'my-icons'
}
},
'digital-numbers': {
dirs: [path.resolve(__dirname, 'icons/digital-numbers')],
metadata: {
name: 'digital-numbers'
}
},
'type-icons': {
dirs: {
hero: path.resolve(__dirname, '../node_modules/heroicons/24/solid'),
tabler: path.resolve(__dirname, '../node_modules/@tabler/icons/icons')
},
// test exclude, - in filename before onSVGName
exclude: ['*-*'],
// outputMetadata: false,
// outputRuntime: false,
metadata: {
readme: 'open source icons'
}
},
'tiny-icons': {
dirs: path.resolve(__dirname, '../node_modules/super-tiny-icons/images/svg'),
onSVGName: function(name, item) {
name = name.toLowerCase();
name = name.split('_').join('-');
return this.onSVGNameDefault(name, item);
},
onSVGDocument: function($svg, item, $) {
tiktokHandler($svg, item, $);
},
metadata: {
readme: 'super-tiny-icons/images/svg'
}
}
};
const rows = [];
Object.keys(tests).forEach((id) => {
console.log('====================================================');
console.log(`generating ${EC.cyan(id)} ...`);
const options = tests[id];
// silent test
// options.silent = true;
options.id = id;
options.outputDir = path.resolve(__dirname, 'dist');
const time_start = Date.now();
const metadata = svgMinifier(options);
const duration = `${Date.now() - time_start} ms`;
rows.push([id, duration]);
console.log(`generated ${EC.cyan(id)}: ${EC.green(metadata.icons.length)} (${EC.magenta(duration)})`);
});
CG({
columns: ['Name', {
name: 'Duration',
align: 'right'
}],
rows
});
/*
┌─────────────────┬──────────┐
│ Name │ Duration │
├─────────────────┼──────────┤
│ my-icons │ 187 ms │
│ digital-numbers │ 58 ms │
│ type-icons │ 1450 ms │
│ tiny-icons │ 494 ms │
└─────────────────┴──────────┘
*/
console.log('================================================================');
console.log('please open test/index.html test/symbol.html to check results');