Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Add a nice little progress bar while downloading binary
Browse files Browse the repository at this point in the history
Forked from #1649.

This PR adds a small ascii progress bar to the binary download.
Stalled installations make up a steady background noise of our
issues. It's my hope that by making the binary fetch more
transparent we can stem the tide of those issues.

In order to address @saper's [concerns][1] this progress bar will
respect npm's `progress` config flag.

Downloading
```
Start downloading binary at https://github.com/sass/node-sass/releases/download/v3.8.0/darwin-x64-48_binding.node
Total 2602136 [===============          ] 1566256 60% 4.9s
```
Success
```
Start downloading binary at https://github.com/sass/node-sass/releases/download/v3.8.0/darwin-x64-48_binding.node
Total 2602136 [=========================] 2602136 100% 0.0s
Binary downloaded and installed at /tmp/node-sass/vendor/darwin-x64-48/binding.node
```

[1]: #1649 (comment)
  • Loading branch information
Skylar.Zheng authored and xzyfer committed Sep 1, 2016
1 parent 9525d5c commit 42f6fec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"mkdirp": "^0.5.1",
"nan": "^2.3.2",
"node-gyp": "^3.3.1",
"progress": "^1.1.8",
"request": "^2.61.0",
"sass-graph": "^2.1.1"
},
Expand Down
16 changes: 16 additions & 0 deletions scripts/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var fs = require('fs'),
path = require('path'),
sass = require('../lib/extensions'),
request = require('request'),
ProgressBar = require('progress'),
pkg = require('../package.json');

/**
Expand Down Expand Up @@ -56,6 +57,8 @@ function download(url, dest, cb) {
}
};

console.log('Start downloading binary at', url);

try {
request(url, options, function(err, response) {
if (err) {
Expand All @@ -70,6 +73,19 @@ function download(url, dest, cb) {
if (successful(response)) {
response.pipe(fs.createWriteStream(dest));
}

if (process.env.npm_config_progress) {
var bar = new ProgressBar('Total :total [:bar] :current :percent :etas', {
complete: '=',
incomplete: ' ',
width: 25,
total: parseInt(response.headers['content-length'])
});

response.on('data', function(chunk) {
bar.tick(chunk.length);
});
}
});
} catch (err) {
cb(err);
Expand Down

0 comments on commit 42f6fec

Please sign in to comment.