2021-04-02 08:04:42 +00:00
|
|
|
const { default: svgr } = require('@svgr/core')
|
|
|
|
const fs = require('fs')
|
|
|
|
|
|
|
|
|
|
|
|
const dir = './svgr_raw/'
|
|
|
|
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
|
|
|
|
const output = ['import * as React from "react";']
|
|
|
|
const names = []
|
|
|
|
|
|
|
|
try {
|
|
|
|
const files = await fs.promises.readdir(dir);
|
|
|
|
for (const file of files) {
|
2021-04-08 08:48:29 +00:00
|
|
|
console.log(file)
|
2021-04-02 08:04:42 +00:00
|
|
|
const res = await fs.promises.readFile(dir+file, 'utf-8')
|
|
|
|
let name = file.split('.')[0]
|
|
|
|
name = name[0].toUpperCase() + name.slice(1)
|
|
|
|
names.push(name)
|
2021-04-02 19:33:09 +00:00
|
|
|
const jsx = await svgr(res, { icon: true,
|
|
|
|
plugins: ['@svgr/plugin-svgo', '@svgr/plugin-jsx', '@svgr/plugin-prettier'],
|
|
|
|
replaceAttrValues: { '#000': 'currentColor' }
|
|
|
|
}, { componentName: name })
|
2021-04-02 08:04:42 +00:00
|
|
|
const split = jsx.split('\n')
|
|
|
|
output.push(split.slice(1,split.length-2).join('\n'))
|
|
|
|
}
|
|
|
|
|
|
|
|
output.push(`export { ${names.join(', ')} };`)
|
|
|
|
|
|
|
|
|
2021-04-08 08:48:29 +00:00
|
|
|
const data = fs.writeFileSync('../src/react/icons.jsx', output.join(''))
|
2021-04-02 08:04:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
main()
|