forked from oblador/react-native-vector-icons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-material-icons.js
executable file
·53 lines (45 loc) · 1.32 KB
/
generate-material-icons.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
#!/usr/bin/env node
'use strict';
var argv = require('yargs')
.usage('Usage: $0 [options] path/to/codepoints \nFor default template please provide --componentName and --fontFamily')
.demand(1)
.default('t', __dirname + '/template/iconSet.tpl')
.describe('t', 'Template in lodash format')
.alias('t', 'template')
.describe('o', 'Save output to file, defaults to STDOUT')
.alias('o', 'output')
.argv;
var _ = require('lodash');
var fs = require('fs');
var extractGlyphMapFromCodepoints = function(fileName) {
var codepoints = fs.readFileSync(fileName, { encoding: 'utf8' }).split('\n');
var glyphMap = {};
codepoints.forEach(function(point) {
var parts = point.split(' ');
if(parts.length === 2) {
glyphMap[parts[0].replace(/_/g, '-')] = parseInt(parts[1], 16);
}
});
return glyphMap;
};
var template;
if(argv.template) {
template = fs.readFileSync(argv.template, { encoding: 'utf8' });
}
var data = _.omit(argv, '_ $0 o output t template'.split(' '));
var glyphMap = extractGlyphMapFromCodepoints(argv._[0]);
var content = JSON.stringify(glyphMap, null, ' ');
if(template) {
var compiled = _.template(template);
data = data || {};
data.glyphMap = content;
content = compiled(data);
}
if(argv.output) {
fs.writeFileSync(
argv.output,
content
);
} else {
console.log(content);
}