Gitako/generate-octicon.js
EnixCoda f95b31bb25 feat(icon): use SVG octicon
generate SVG files with generate-octicon.js
load as react component thanks to svg-loader
bundle
size decreased from 48kb to 26kb!
2018-02-08 13:05:16 +08:00

33 lines
794 B
JavaScript

const octicons = require('octicons')
const fs = require('fs')
const pathToIconsFolder = `${__dirname}/src/assets/icons/octicons`
function generateIconSVGFiles() {
Object.values(octicons).forEach(icon => {
fs.writeFile(
`${pathToIconsFolder}/${icon.symbol}.svg`,
icon.toSVG({ xmlns: 'http://www.w3.org/2000/svg' }),
err => {
if (err) throw err
}
)
})
}
fs.exists(pathToIconsFolder, exists => {
if (exists) {
fs.lstat(pathToIconsFolder, (err, stats) => {
if (err) throw err
if (!stats.isDirectory()) {
throw new Error(`${pathToIconsFolder} is not a folder!`)
}
generateIconSVGFiles()
})
} else {
fs.mkdir(pathToIconsFolder, err => {
if (err) throw err
generateIconSVGFiles()
})
}
})