Created
August 18, 2016 12:39
-
-
Save vincentbel/8c87ed0cea88d1bd6862dc0a891c9997 to your computer and use it in GitHub Desktop.
Export material design 24px svg icons
This file contains hidden or 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 glob = require('glob') | |
| const path = require('path') | |
| const execSync = require('child_process').execSync | |
| const savedDir = path.join(__dirname, '__exported_svg') | |
| execSync(`mkdir -p ${savedDir}`) | |
| const count = glob.sync(`${__dirname}/*/`) | |
| .map(typePath => { | |
| const svgs = glob.sync(`${typePath}/svg/production/ic_*_24px.svg`) | |
| svgs.forEach(p => { | |
| const fileName = path.basename(p, '.svg') | |
| const matchRes = fileName.match(/^ic_(.*)_24px$/) | |
| if (!matchRes) { | |
| throw new Error(`/^ic_(.*)_24px$/ can't match filename: ${fileName}`) | |
| } | |
| const newFileName = matchRes[1].replace(/_/g, '-') | |
| const cmd = `cp ${p} ${savedDir}/${newFileName}.svg` | |
| console.log(cmd) | |
| execSync(cmd) | |
| }) | |
| return svgs.length | |
| }) | |
| .reduce((pre, cur) => pre + cur, 0) | |
| console.log(`${count} svgs exported`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment