-
Notifications
You must be signed in to change notification settings - Fork 29
/
build.js
45 lines (36 loc) · 1.01 KB
/
build.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
'use strict'
const { readdirSync, readFileSync, writeFileSync } = require('fs')
const { join, parse } = require('path')
const noneSquareIconWidths = {
awesome: 20,
codeclimate: 18,
commonwl: 10,
devrant: 12,
lgtm: 19,
now: 15,
npm: 20,
peertube: 10,
zeit: 15
}
const generateIcons = iconFolder => readdirSync(iconFolder).reduce((icons, filename) => {
const { name, ext } = parse(filename)
const imageType = {
'.svg': 'svg+xml',
'.png': 'png'
}[ext]
if (!imageType) return icons
const iconFile = join(iconFolder, filename)
const svgSource = readFileSync(iconFile, 'utf8')
const b64 = Buffer.from(svgSource).toString('base64')
icons[name] = {
base64: `data:image/${imageType};base64,${b64}`,
width: noneSquareIconWidths[name] || 13,
height: 13
}
return icons
}, {})
const inputDir = join(__dirname, 'icons')
const outFile = join(__dirname, 'icons.json')
const icons = generateIcons(inputDir)
const json = JSON.stringify(icons, null, 2)
writeFileSync(outFile, json)