-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
genSprites.js
46 lines (30 loc) · 1.21 KB
/
genSprites.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// create svg spritesheets from icons
const fs = require('fs')
const path = require('path')
function genSprites(folder) {
const dir = path.join(__dirname, 'icons', folder)
let output = '<svg xmlns="http://www.w3.org/2000/svg">\n\n'
fs.readdirSync(dir).forEach(file => {
if (path.extname(file) === '.svg') {
let svg = fs.readFileSync(path.join(dir, file), 'utf8')
let fileName = path.basename(file, '.svg')
svg = svg.replace('<svg', '<symbol id="' + fileName + '"');
svg = svg.replace('</svg>', '</symbol>');
// remove not needed tags from each svg string
svg = svg.replace('xmlns="http://www.w3.org/2000/svg"', 'preserveAspectRatio="xMidYMid meet"');
svg = svg.replace('width="64"', 'width="100%"');
svg = svg.replace('height="64"', 'height="100%"');
// replace multiple consecutive spaces with single space
svg = svg.replace(/\s{2,}/g, ' ');
output += svg + '\n\n';
}
});
output += '\n\n</svg>'
let fileName = 'fusion-' + folder + '.svg'
let filePath = path.join(__dirname, 'sprites', fileName)
fs.writeFileSync(filePath, output)
console.log(`${fileName} generated`)
}
genSprites('coins')
genSprites('interface')
genSprites('web3')