-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ts
51 lines (43 loc) · 1011 Bytes
/
build.ts
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
import { appendFileSync, mkdirSync, readFileSync } from 'fs';
import { glob } from 'glob';
import { Parser } from 'htmlparser2';
import _ from 'lodash';
const base = 'node_modules/heroicons/';
const variants = [
{
name: 'solid',
path: '24/solid/',
},
{
name: 'outline',
path: '24/outline/',
},
{
name: 'mini',
path: '20/solid/',
},
{
name: 'micro',
path: '16/solid/',
},
];
let svg = '';
const parser = new Parser({
onopentag(name, attr) {
if (name === 'path') {
if (svg.length > 0) svg += ' ';
svg += attr['d'];
}
},
});
for (const { name, path } of variants) {
mkdirSync(name);
for (const file of glob.sync('*.svg', { cwd: base + path }).reverse()) {
svg = '';
parser.write(readFileSync(base + path + file, { encoding: 'utf-8' }));
const filename = file.split('.')[0]!;
appendFileSync(name + '/index.ts', `export const ${_.camelCase(filename)}: string = "${svg}";\n`, {
encoding: 'utf-8',
});
}
}