blob: faf6b7bf22d362ef52ef76d2c74ce45e26ee9eeb [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001const fs = require('fs')
2const path = require('path')
3const { EOL } = require('os')
4
5const SRC = path.resolve(__dirname + '/../iconfont/codepoints')
6const DST_JSON = path.resolve(__dirname + '/../iconfont/codepoints.json')
7const DST_SCSS = path.resolve(__dirname + '/../iconfont/codepoints.scss')
8
9const lines = fs
10 .readFileSync(SRC)
11 .toString()
12 .split(EOL)
13const codepoints = {}
14let map = ''
15
16lines.forEach(line => {
17 const [name, codepoint] = line
18 .trim()
19 .split(' ')
20 .map(v => v.trim())
21 if (!name || !codepoint) {
22 return
23 }
24 codepoints[name] = codepoint
25 map += ` "${name}": ${codepoint},${EOL}`
26})
27
28map = map.replace(/,\s*$/, '')
29const mapName = '$material-icons-codepoints'
30map = `${mapName}: () !default;
31${mapName}: map-merge((
32${map}
33), ${mapName});
34`
35
36fs.writeFileSync(DST_JSON, JSON.stringify(codepoints, null, 2))
37fs.writeFileSync(DST_SCSS, map)