forked from dan-gamble/postcss-font-awesome
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgenerateIconConfig.js
52 lines (42 loc) · 1.36 KB
/
generateIconConfig.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
var path = require('path');
var fs = require('fs');
var https = require('https');
var config = {
src: path.resolve(
__dirname, 'node_modules', 'font-awesome', 'scss', '_variables.scss'
),
dest: './icons.json'
};
var varsUrl = 'https://raw.githubusercontent.com/FortAwesome/Font-Awesome/';
varsUrl += 'v4.7.0/scss/_variables.scss';
https.request(varsUrl, function (res) {
if (res.statusCode !== 200) {
throw new Error(
'Failed to fetch variables from Github, got HTTP ' + res.statusCode
);
}
var data = '';
res.setEncoding('utf8');
res.on('data', function (chunk) {
data += chunk;
});
res.on('end', function () {
var lines = data.split('\n').filter(n => {
return n !== undefined && n !== '' && n.startsWith('$fa-var-');
});
var icons = {};
for (var line of lines) {
var icon = line.substring(0, line.indexOf(':'))
.replace('$fa-var-', '');
var code = line.substring(line.indexOf('\\f'), line.indexOf('";'))
.replace('\\f', '');
icons[icon] = code;
}
fs.writeFile(config.dest, JSON.stringify(icons), function (error) {
if (error) {
throw error;
}
console.log('Icons file created');
});
});
}).end();