Created
July 17, 2020 09:50
-
-
Save lgk-bsw/d6bf964d73c6ec7789c9ce7b2dabc5bd to your computer and use it in GitHub Desktop.
SVG to React generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require("fs"); | |
const path = require("path"); | |
const svgToJsx = require("svg-to-jsx"); | |
const parser = require("fast-xml-parser"); | |
let componentCodes = []; | |
function main() { | |
const dir = fs.readdirSync("."); | |
dir.forEach(file => { | |
const extension = path.extname(file); | |
console.log(extension); | |
if (extension.toLowerCase() === ".svg") { | |
const svg = fs.readFileSync(file, "utf-8"); | |
svgToJsx(svg, (error, jsx) => { | |
if (error) console.error(error); | |
console.log(jsx); | |
const jsonObj = parser.parse(svg); | |
console.log(jsonObj); | |
componentCodes.push(``); | |
}); | |
} | |
}); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment