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

Commit

Permalink
Use npmlog for all install script output
Browse files Browse the repository at this point in the history
In for a penny in for a pound. I also  noticed that #1786 resulted
in some funky looking console output. I've taken this opportunity to
tidy up our install script output whilst maintaining the information
useful for debugging install issues.

```
> [email protected] install /Users/xzyfer/Projects/Sass/upstream/node-sass
> node scripts/install.js

http node-sass install Downloading binary from https://github.com/sass/node-sass/releases/download/v3.11.3/darwin-x64-47_binding.node
http node-sass install Download complete
info node-sass install Binary saved at /Users/xzyfer/Projects/Sass/upstream/node-sass/vendor/darwin-x64-47/binding.node

> [email protected] postinstall /Users/xzyfer/Projects/Sass/upstream/node-sass
> node scripts/build.js

info node-sass build Binary found at /Users/xzyfer/Projects/Sass/upstream/node-sass/vendor/darwin-x64-47/binding.node
info node-sass build Testing binary
info node-sass build Binary is fine

> [email protected] prepublish /Users/xzyfer/Projects/Sass/upstream/node-sass
> not-in-install && node scripts/prepublish.js || in-install
```
  • Loading branch information
xzyfer committed Nov 13, 2016
1 parent 5c7fb7f commit 29f6d7c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
36 changes: 21 additions & 15 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
* node-sass: scripts/build.js
*/

var eol = require('os').EOL,
pkg = require('../package.json'),
var pkg = require('../package.json'),
fs = require('fs'),
mkdir = require('mkdirp'),
path = require('path'),
spawn = require('cross-spawn'),
log = require('npmlog'),
sass = require('../lib/extensions');

/**
Expand All @@ -28,23 +28,23 @@ function afterBuild(options) {

mkdir(path.dirname(install), function(err) {
if (err && err.code !== 'EEXIST') {
console.error(err.message);
log.error('node-sass build', err.message);
return;
}

fs.stat(target, function(err) {
if (err) {
console.error('Build succeeded but target not found');
log.error('node-sass build', 'Build succeeded but target not found');
return;
}

fs.rename(target, install, function(err) {
if (err) {
console.error(err.message);
log.error('node-sass build', err.message);
return;
}

console.log('Installed in "' + install + '"');
log.info('node-sass build', 'Installed to %s', install);
});
});
});
Expand Down Expand Up @@ -76,8 +76,8 @@ function manageProcess(proc, cb) {
*/

function initSubmodules(cb) {
console.log('Detected a git install');
console.log('Cloning libSass into src/libsass');
log.info('node-sass build', 'Detected a git install');
log.info('node-sass build', 'Cloning LibSass into src/libsass');

var clone = spawn('git', ['clone', 'https://github.com/sass/libsass.git', './src/libsass']);
manageProcess(clone, function(err) {
Expand All @@ -86,7 +86,7 @@ function initSubmodules(cb) {
return;
}

console.log('Checking out libsass to ' + pkg.libsass);
log.info('node-sass build', 'Checking out LibSass to %s', pkg.libsass);

var checkout = spawn('git', ['checkout', pkg.libsass], { cwd: './src/libsass' });
manageProcess(checkout, function(err) {
Expand Down Expand Up @@ -137,7 +137,7 @@ function build(options) {
return ['--', subject, '=', process.env[subject.toUpperCase()] || ''].join('');
})).concat(options.args);

console.log(['Building:', process.execPath].concat(args).join(' '));
log.info('node-sass build', [process.execPath].concat(args).join(' '));

var proc = spawn(process.execPath, args, {
stdio: [0, 1, 2]
Expand All @@ -146,11 +146,15 @@ function build(options) {
proc.on('exit', function(errorCode) {
if (!errorCode) {
afterBuild(options);

return;
}

console.error(errorCode === 127 ? 'node-gyp not found!' : 'Build failed');
if (errorCode === 127 ) {
log.error('node-sass build', 'node-gyp not found!');
} else {
log.error('node-sass build', 'Build failed with error code: %d', errorCode);
}

process.exit(1);
});
});
Expand Down Expand Up @@ -203,16 +207,18 @@ function testBinary(options) {
return build(options);
}

console.log('"' + sass.getBinaryPath() + '" exists.', eol, 'testing binary.');
log.info('node-sass build', 'Binary found at %s', sass.getBinaryPath());
log.info('node-sass build', 'Testing binary');

try {
require('../').renderSync({
data: 's { a: ss }'
});

console.log('Binary is fine; exiting.');
log.info('node-sass build', 'Binary is fine');
} catch (e) {
console.log(['Problem with the binary:', e, 'Manual build incoming.'].join(eol));
log.error('node-sass build', 'Binary has a problem: %s', e);
log.info('node-sass build', 'Building the binary locally');

return build(options);
}
Expand Down
7 changes: 4 additions & 3 deletions scripts/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function download(url, dest, cb) {
return response.statusCode >= 200 && response.statusCode < 300;
};

log.http('node-sass install', 'Start downloading binary at ' + url);
log.http('node-sass install', 'Downloading binary from %s', url);

try {
request(url, downloadOptions(), function(err, response) {
Expand All @@ -57,12 +57,13 @@ function download(url, dest, cb) {
} else if (!successful(response)) {
reportError(['HTTP error', response.statusCode, response.statusMessage].join(' '));
} else {
log.http('node-sass install', 'Download complete');
cb();
}
})
.on('response', function(response) {
var length = parseInt(response.headers['content-length'], 10);
var progress = log.newItem(url, length);
var progress = log.newItem('', length);

if (successful(response)) {
response.pipe(fs.createWriteStream(dest));
Expand Down Expand Up @@ -108,7 +109,7 @@ function checkAndDownloadBinary() {
return;
}

log.info('node-sass install', 'Binary downloaded and installed at ' + sass.getBinaryPath());
log.info('node-sass install', 'Binary saved at %s', sass.getBinaryPath());
});
});
}
Expand Down

0 comments on commit 29f6d7c

Please sign in to comment.