-
Notifications
You must be signed in to change notification settings - Fork 0
/
icons.js
50 lines (40 loc) · 1.32 KB
/
icons.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
const path = require('path');
const fs = require('fs-extra');
const iconsPath = './node_modules/heroicons';
const buildPath = './dist/icons';
const componentTemplate = (name, svg) => {
return 'export default function() { \n' + '\treturn `' + svg + '`' + '\n};';
};
async function main() {
const iconDirsPath = path.join(__dirname, iconsPath);
const categories = ['outline', 'solid'];
const icons = [];
const categoryByOriginCategory = {
outline: 'outline',
solid: 'solid',
};
fs.removeSync(buildPath);
for (const originCategory of categories) {
const categoryPath = path.join(iconDirsPath, originCategory);
const filenames = await fs.readdir(categoryPath);
const iconsByCategory = filenames.map((filename) => {
const [name] = filename.split('.');
return {
name,
path: path.join(categoryPath, filename),
category: categoryByOriginCategory[originCategory],
};
});
icons.push(...iconsByCategory);
}
for (const icon of icons) {
// Read svg as string
const svg = await fs.readFile(icon.path, 'utf8');
const filepath = `${buildPath}/${icon.category}/${icon.name}.js`;
await fs.ensureDir(path.dirname(filepath));
await fs.writeFile(filepath, componentTemplate(icon.name, svg), 'utf8');
}
}
main().catch((err) => {
console.error(err);
});