Commit ba3a2e01 by Michael Mifsud Committed by GitHub

Merge pull request #1694 from xzyfer/feat/progress-bar

Add a nice little progress bar while downloading binary
parents 7bf34bee 25b54a7a
...@@ -64,6 +64,7 @@ ...@@ -64,6 +64,7 @@
"mkdirp": "^0.5.1", "mkdirp": "^0.5.1",
"nan": "^2.3.2", "nan": "^2.3.2",
"node-gyp": "^3.3.1", "node-gyp": "^3.3.1",
"npmlog": "^4.0.0",
"request": "^2.61.0", "request": "^2.61.0",
"sass-graph": "^2.1.1" "sass-graph": "^2.1.1"
}, },
......
...@@ -8,6 +8,7 @@ var fs = require('fs'), ...@@ -8,6 +8,7 @@ var fs = require('fs'),
path = require('path'), path = require('path'),
sass = require('../lib/extensions'), sass = require('../lib/extensions'),
request = require('request'), request = require('request'),
log = require('npmlog'),
pkg = require('../package.json'); pkg = require('../package.json');
/** /**
...@@ -56,6 +57,8 @@ function download(url, dest, cb) { ...@@ -56,6 +57,8 @@ function download(url, dest, cb) {
} }
}; };
console.log('Start downloading binary at', url);
try { try {
request(url, options, function(err, response) { request(url, options, function(err, response) {
if (err) { if (err) {
...@@ -67,9 +70,24 @@ function download(url, dest, cb) { ...@@ -67,9 +70,24 @@ function download(url, dest, cb) {
} }
}) })
.on('response', function(response) { .on('response', function(response) {
var length = parseInt(response.headers['content-length'], 10);
var progress = log.newItem(url, length);
if (successful(response)) { if (successful(response)) {
response.pipe(fs.createWriteStream(dest)); response.pipe(fs.createWriteStream(dest));
} }
// The `progress` is true by default. However if it has not
// been explicitly set it's `undefined` which is considered
// as far as npm is concerned.
if (process.env.npm_config_progress !== false) {
log.enableProgress();
response.on('data', function(chunk) {
progress.completeWork(chunk.length);
})
.on('end', progress.finish);
}
}); });
} catch (err) { } catch (err) {
cb(err); cb(err);
......
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