-
Notifications
You must be signed in to change notification settings - Fork 32
/
NIconGenerator.js
41 lines (36 loc) · 1.22 KB
/
NIconGenerator.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
const fs = require('fs')
const path = require('path')
const ASSETS_DIR = `${process.cwd()}/src/assets`
const PATH_REGEX = /d="(.*)" /
const icons = {}
/**
* Generates icon objects with keyname and svg paths
*/
const generateIconPaths = async () => {
try{
let files = await fs.promises.readdir(path.resolve(`${ASSETS_DIR}/svgs`))
for (let index = 0; index < files.length; index++) {
const file = files[index];
if(file.includes('ic_') && file.includes('.svg')){
let svgFile = await fs.promises.readFile(path.resolve(`${ASSETS_DIR}/svgs/${file}`))
let keyName = file.replace(`ic_`, '').replace('.svg', '')
let result = PATH_REGEX.exec(svgFile)
icons[keyName] = result.slice(1)[0]
}
}
}catch(error){
console.error(error)
}
}
const exportIconPaths = async () => {
await generateIconPaths()
// Write to FS
const ICONS_FILE_PATH = `${ASSETS_DIR}/icons.json`
await fs.promises.writeFile(ICONS_FILE_PATH, JSON.stringify(icons), 'utf-8')
}
// generateIconPaths().then(() => {
// console.log(icons)
// })
exportIconPaths().then(() => {
console.log("Icons exported successfully")
})