Copybara bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame] | 1 | const fs = require('fs') |
| 2 | const path = require('path') |
| 3 | const { EOL } = require('os') |
| 4 | |
| 5 | const SRC = path.resolve(__dirname + '/../iconfont/codepoints') |
| 6 | const DST_JSON = path.resolve(__dirname + '/../iconfont/codepoints.json') |
| 7 | const DST_SCSS = path.resolve(__dirname + '/../iconfont/codepoints.scss') |
| 8 | |
| 9 | const lines = fs |
| 10 | .readFileSync(SRC) |
| 11 | .toString() |
| 12 | .split(EOL) |
| 13 | const codepoints = {} |
| 14 | let map = '' |
| 15 | |
| 16 | lines.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 | |
| 28 | map = map.replace(/,\s*$/, '') |
| 29 | const mapName = '$material-icons-codepoints' |
| 30 | map = `${mapName}: () !default; |
| 31 | ${mapName}: map-merge(( |
| 32 | ${map} |
| 33 | ), ${mapName}); |
| 34 | ` |
| 35 | |
| 36 | fs.writeFileSync(DST_JSON, JSON.stringify(codepoints, null, 2)) |
| 37 | fs.writeFileSync(DST_SCSS, map) |