Commit 250d6cf9 by Rubén Norte

General code improvements in install script

parent 71e53c52
...@@ -2,7 +2,9 @@ var fs = require('fs'), ...@@ -2,7 +2,9 @@ var fs = require('fs'),
path = require('path'), path = require('path'),
request = require('request'), request = require('request'),
mkdirp = require('mkdirp'), mkdirp = require('mkdirp'),
exec = require('shelljs').exec; exec = require('shelljs').exec,
npmconf = require('npmconf'),
packageInfo = require('../package.json');
require('../lib/extensions'); require('../lib/extensions');
...@@ -39,25 +41,26 @@ function download(url, dest, cb) { ...@@ -39,25 +41,26 @@ function download(url, dest, cb) {
*/ */
function applyProxy(options, cb) { function applyProxy(options, cb) {
require('npmconf').load({}, function (er, conf) { npmconf.load({}, function (er, conf) {
var getProxyFromEnv = true; var proxyUrl;
['https-proxy', 'proxy', 'http-proxy'].forEach(function(setting) {
var proxyUrl = conf.get(setting); if (!er) {
['https-proxy', 'proxy', 'http-proxy'].some(function(setting) {
if(proxyUrl && proxyUrl === require('url').parse(proxyUrl)) { var npmProxyUrl = conf.get(setting);
options.proxy = proxyUrl; if (npmProxyUrl) {
getProxyFromEnv = false; proxyUrl = npmProxyUrl;
cb(options); return true;
return; }
} });
}); }
if(getProxyFromEnv) { if (!proxyUrl) {
var env = process.env; var env = process.env;
options.proxy = env.HTTPS_PROXY || env.https_proxy || env.HTTP_PROXY || env.http_proxy; proxyUrl = env.HTTPS_PROXY || env.https_proxy || env.HTTP_PROXY || env.http_proxy;
cb(options);
} }
options.proxy = proxyUrl;
cb(options);
}); });
} }
...@@ -67,7 +70,7 @@ function applyProxy(options, cb) { ...@@ -67,7 +70,7 @@ function applyProxy(options, cb) {
* @api private * @api private
*/ */
function exists() { function checkAndFetchBinaries() {
fs.exists(path.join(__dirname, '..', 'vendor', process.sassBinaryName), function (exists) { fs.exists(path.join(__dirname, '..', 'vendor', process.sassBinaryName), function (exists) {
if (exists) { if (exists) {
return; return;
...@@ -86,7 +89,7 @@ function exists() { ...@@ -86,7 +89,7 @@ function exists() {
function fetch() { function fetch() {
var url = [ var url = [
'https://raw.githubusercontent.com/sass/node-sass-binaries/v', 'https://raw.githubusercontent.com/sass/node-sass-binaries/v',
require('../package.json').version, '/', process.sassBinaryName, packageInfo.version, '/', process.sassBinaryName,
'/binding.node' '/binding.node'
].join(''); ].join('');
var dir = path.join(__dirname, '..', 'vendor', process.sassBinaryName); var dir = path.join(__dirname, '..', 'vendor', process.sassBinaryName);
...@@ -122,4 +125,4 @@ if (process.env.SKIP_SASS_BINARY_DOWNLOAD_FOR_CI) { ...@@ -122,4 +125,4 @@ if (process.env.SKIP_SASS_BINARY_DOWNLOAD_FOR_CI) {
* Run * Run
*/ */
exists(); checkAndFetchBinaries();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment