Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save vincentbel/8c87ed0cea88d1bd6862dc0a891c9997 to your computer and use it in GitHub Desktop.

Select an option

Save vincentbel/8c87ed0cea88d1bd6862dc0a891c9997 to your computer and use it in GitHub Desktop.
Export material design 24px svg icons
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