Skip to content

Commit

Permalink
Use plain https module for post-install script
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Aug 8, 2016
1 parent 21db5ee commit e6902b5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
51 changes: 35 additions & 16 deletions generateIconConfig.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var path = require('path');
var fs = require('fs');
var req = require('request');
var https = require('https');

var config = {
src: path.resolve(
Expand All @@ -9,25 +9,44 @@ var config = {
dest: './icons.json'
};

req.get('https://raw.githubusercontent.com/FortAwesome/Font-Awesome/master/scss/_variables.scss', function (e, d, data) {
if (e) console.log(e);
var varsUrl = 'https://raw.githubusercontent.com/FortAwesome/Font-Awesome/';
varsUrl += 'master/scss/_variables.scss';

var lines = data.split('\n').filter(n => {
return n !== undefined && n !== '' && n.startsWith('$fa-var-');
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;
});
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', '');
res.on('end', function () {
var lines = data.split('\n').filter(n => {
return n !== undefined && n !== '' && n.startsWith('$fa-var-');
});
var icons = {};

icons[icon] = code;
}
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) console.log(error);
fs.writeFile(config.dest, JSON.stringify(icons), function (error) {
if (error) {
throw error;
}

console.log('Icons file created');
console.log('Icons file created');
});
});
});
}).end();
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
},
"homepage": "https://github.com/dan-gamble/postcss-font-awesome",
"dependencies": {
"postcss": "^5.0.14",
"request": "^2.72.0"
"postcss": "^5.0.14"
},
"devDependencies": {
"ava": "^0.14.0",
Expand Down

0 comments on commit e6902b5

Please sign in to comment.