Skip to content

Commit 3b71c64

Browse files
committed
refactor: move map reading function out for reuse
1 parent 5e1f78c commit 3b71c64

2 files changed

Lines changed: 25 additions & 13 deletions

File tree

scripts/build.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const fs = require('fs');
22
const path = require('path');
3+
const { readMap } = require('./read-map');
34

45
const version = process.argv[2];
56

@@ -11,22 +12,11 @@ const buildFolder = path.join(scriptDir, '..', "build");
1112
const buildRawFolder = path.join(buildFolder, "raw");
1213
const atlas = {}
1314
const files = fs.readdirSync(mapsFolder)
14-
const isRule = (line) => {
15-
return line.length < 10 && line.indexOf('=') > -1
16-
}
17-
const isComment = (line) => !isRule(line)
1815
files.forEach((file) => {
1916
const filePath = path.join(mapsFolder, file);
20-
21-
const data = fs.readFileSync(filePath, 'utf8')
17+
const fontMap = readMap(filePath);
2218
const fontName = path.parse(file).name;
23-
const fontMap = {};
24-
data.split('\n').forEach(l => {
25-
l = l.trim();
26-
if (isComment(l)) return;
27-
const [lhs, rhs] = l.split('=').map(w => w.trim());
28-
if (lhs) fontMap[lhs] = rhs;
29-
})
19+
3020
atlas[fontName] = fontMap;
3121
});
3222
const jsBuildPath = path.join(buildRawFolder, 'unicode-conversion-maps.mjs');

scripts/read-map.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const fs = require('fs');
2+
3+
const isRule = (line) => {
4+
return line.length < 10 && line.indexOf('=') > -1
5+
}
6+
const isComment = (line) => !isRule(line)
7+
8+
const readMap = (filePath) => {
9+
const data = fs.readFileSync(filePath, 'utf8')
10+
const fontMap = {};
11+
data.split('\n').forEach(l => {
12+
l = l.trim();
13+
if (isComment(l)) return;
14+
const [lhs, rhs] = l.split('=').map(w => w.trim());
15+
if (lhs) fontMap[lhs] = rhs;
16+
})
17+
return fontMap
18+
}
19+
20+
module.exports = {
21+
readMap
22+
}

0 commit comments

Comments
 (0)