-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild-material-symbols-js.js
64 lines (46 loc) · 1.75 KB
/
build-material-symbols-js.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const fs = require('fs')
const _ = require('lodash')
const logger = require('./logger')
if (!fs.existsSync('./dist')) {
fs.mkdirSync('./dist')
}
(function constructor() {
'use strict'
let codepoints = fs.readFileSync('./lib/templates/materialsymbols/MaterialSymbolsOutlined[FILL,GRAD,opsz,wght].codepoints', 'utf8')
codepoints += fs.readFileSync('./lib/templates/materialsymbols/MaterialSymbolsRounded[FILL,GRAD,opsz,wght].codepoints', 'utf8')
codepoints += fs.readFileSync('./lib/templates/materialsymbols/MaterialSymbolsSharp[FILL,GRAD,opsz,wght].codepoints', 'utf8')
const uniqueCodepoints = _.map(_.uniq(codepoints.split('\n').sort()), rule => {
if (rule !== '') {
const separado = rule.split(' ')
return {
selector: separado[0],
property: separado[1]
}
}
})
let fileContent = fs.readFileSync('./lib/templates/materialsymbols/template.js', 'utf8')
fileContent += '\n' + fs.readFileSync('./lib/templates/icon-functions.js', 'utf8')
let exportIcons = '\nconst icons = {\n'
_.each(uniqueCodepoints, rule => {
if (rule) {
exportIcons += `\t'${prettifyFontName(rule.selector)}': '\\u${rule.property}',\n`
}
})
exportIcons += '};\n'
exportIcons += 'exports.icons = icons\n'
exportIcons += '\nconst iconKeys = Object.keys(icons)\n'
fileContent += exportIcons
fs.writeFileSync('./dist/materialsymbols.js', fileContent, err => {
throw err
})
logger.file('./dist/materialsymbols.js')
}())
function prettifyFontName(str) {
const temp = str.split('_'); let i; let pretty
for (i = 0; i < temp.length; i++) {
temp[i] = temp[i].charAt(0).toUpperCase() + temp[i].slice(1)
}
pretty = temp.join('')
pretty = pretty.replace(/^.{1}/g, pretty[0].toLowerCase())
return pretty
}