2018-01-27 20:48:22 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
const svgs = require('./svgs')
|
|
|
|
const path = require('path')
|
|
|
|
const fs = require('fs')
|
|
|
|
const pify = require('pify')
|
|
|
|
const SVGO = require('svgo')
|
|
|
|
const svgo = new SVGO()
|
|
|
|
const $ = require('cheerio')
|
|
|
|
|
|
|
|
const readFile = pify(fs.readFile.bind(fs))
|
|
|
|
const writeFile = pify(fs.writeFile.bind(fs))
|
|
|
|
|
2018-02-09 06:29:29 +00:00
|
|
|
async function main () {
|
2018-01-27 20:48:22 +00:00
|
|
|
let result = (await Promise.all(svgs.map(async svg => {
|
|
|
|
let filepath = path.join(__dirname, '../', svg.src)
|
|
|
|
let content = await readFile(filepath, 'utf8')
|
|
|
|
let optimized = (await svgo.optimize(content))
|
|
|
|
let $optimized = $(optimized.data)
|
|
|
|
let $path = $optimized.find('path').removeAttr('fill')
|
|
|
|
let $symbol = $('<symbol></symbol>')
|
|
|
|
.attr('id', svg.id)
|
|
|
|
.attr('viewBox', `0 0 ${optimized.info.width} ${optimized.info.height}`)
|
2018-01-27 20:55:09 +00:00
|
|
|
.append($('<title></title>').text(svg.title))
|
2018-01-27 20:48:22 +00:00
|
|
|
.append($path)
|
|
|
|
return $.xml($symbol)
|
|
|
|
}))).join('\n')
|
|
|
|
|
|
|
|
result = `<svg xmlns="http://www.w3.org/2000/svg" style="display:none;">\n${result}\n</svg>`
|
|
|
|
|
2018-12-08 20:46:16 +00:00
|
|
|
await writeFile(path.resolve(__dirname, '../assets/icons.svg'), result, 'utf8')
|
2018-01-27 20:48:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
main().catch(err => {
|
|
|
|
console.error(err)
|
|
|
|
process.exit(1)
|
2018-02-09 06:29:29 +00:00
|
|
|
})
|