-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ts
More file actions
27 lines (22 loc) · 693 Bytes
/
build.ts
File metadata and controls
27 lines (22 loc) · 693 Bytes
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
import { appendFileSync, readFileSync } from 'fs';
import { glob } from 'glob';
import { Parser } from 'htmlparser2';
import _ from 'lodash';
const base = 'node_modules/bootstrap-icons/icons';
let svg = '';
const parser = new Parser({
onopentag(name, attr) {
if (name === 'path') {
if (svg.length > 0) svg += ' ';
svg += attr['d'];
}
},
});
for (const file of glob.sync('*.svg', { cwd: base }).reverse()) {
svg = '';
parser.write(readFileSync(base + '/' + file, { encoding: 'utf-8' }));
const filename = file.split('.')[0]!;
appendFileSync('icons.ts', `export const ${_.camelCase('bi-' + filename)}: string = "${svg}";\n`, {
encoding: 'utf-8',
});
}