Commit e54581d7 by Michael Mifsud Committed by GitHub

Merge pull request #1796 from sass/feat/clean-up-script-logging

Use npmlog for all install script output
parents fdda2541 0f2e0044
...@@ -181,9 +181,11 @@ function getBinaryName() { ...@@ -181,9 +181,11 @@ function getBinaryName() {
} else if (pkg.nodeSassConfig && pkg.nodeSassConfig.binaryName) { } else if (pkg.nodeSassConfig && pkg.nodeSassConfig.binaryName) {
binaryName = pkg.nodeSassConfig.binaryName; binaryName = pkg.nodeSassConfig.binaryName;
} else { } else {
binaryName = [process.platform, '-', binaryName = [
process.platform, '-',
process.arch, '-', process.arch, '-',
process.versions.modules].join(''); process.versions.modules
].join('');
} }
return [binaryName, 'binding.node'].join('_'); return [binaryName, 'binding.node'].join('_');
......
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
* node-sass: scripts/build.js * node-sass: scripts/build.js
*/ */
var eol = require('os').EOL, var pkg = require('../package.json'),
pkg = require('../package.json'),
fs = require('fs'), fs = require('fs'),
mkdir = require('mkdirp'), mkdir = require('mkdirp'),
path = require('path'), path = require('path'),
spawn = require('cross-spawn'), spawn = require('cross-spawn'),
log = require('npmlog'),
sass = require('../lib/extensions'); sass = require('../lib/extensions');
/** /**
...@@ -28,23 +28,23 @@ function afterBuild(options) { ...@@ -28,23 +28,23 @@ function afterBuild(options) {
mkdir(path.dirname(install), function(err) { mkdir(path.dirname(install), function(err) {
if (err && err.code !== 'EEXIST') { if (err && err.code !== 'EEXIST') {
console.error(err.message); log.error('node-sass build', err.message);
return; return;
} }
fs.stat(target, function(err) { fs.stat(target, function(err) {
if (err) { if (err) {
console.error('Build succeeded but target not found'); log.error('node-sass build', 'Build succeeded but target not found');
return; return;
} }
fs.rename(target, install, function(err) { fs.rename(target, install, function(err) {
if (err) { if (err) {
console.error(err.message); log.error('node-sass build', err.message);
return; return;
} }
console.log('Installed in "' + install + '"'); log.info('node-sass build', 'Installed to %s', install);
}); });
}); });
}); });
...@@ -76,8 +76,8 @@ function manageProcess(proc, cb) { ...@@ -76,8 +76,8 @@ function manageProcess(proc, cb) {
*/ */
function initSubmodules(cb) { function initSubmodules(cb) {
console.log('Detected a git install'); log.info('node-sass build', 'Detected a git install');
console.log('Cloning libSass into src/libsass'); log.info('node-sass build', 'Cloning LibSass into src/libsass');
var clone = spawn('git', ['clone', 'https://github.com/sass/libsass.git', './src/libsass']); var clone = spawn('git', ['clone', 'https://github.com/sass/libsass.git', './src/libsass']);
manageProcess(clone, function(err) { manageProcess(clone, function(err) {
...@@ -86,7 +86,7 @@ function initSubmodules(cb) { ...@@ -86,7 +86,7 @@ function initSubmodules(cb) {
return; 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' }); var checkout = spawn('git', ['checkout', pkg.libsass], { cwd: './src/libsass' });
manageProcess(checkout, function(err) { manageProcess(checkout, function(err) {
...@@ -128,7 +128,7 @@ function installGitDependencies(options, cb) { ...@@ -128,7 +128,7 @@ function installGitDependencies(options, cb) {
function build(options) { function build(options) {
installGitDependencies(options, function(err) { installGitDependencies(options, function(err) {
if (err) { if (err) {
console.error(err.message); log.error('node-sass build', err.message);
process.exit(1); process.exit(1);
} }
...@@ -137,7 +137,7 @@ function build(options) { ...@@ -137,7 +137,7 @@ function build(options) {
return ['--', subject, '=', process.env[subject.toUpperCase()] || ''].join(''); return ['--', subject, '=', process.env[subject.toUpperCase()] || ''].join('');
})).concat(options.args); })).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, { var proc = spawn(process.execPath, args, {
stdio: [0, 1, 2] stdio: [0, 1, 2]
...@@ -146,11 +146,15 @@ function build(options) { ...@@ -146,11 +146,15 @@ function build(options) {
proc.on('exit', function(errorCode) { proc.on('exit', function(errorCode) {
if (!errorCode) { if (!errorCode) {
afterBuild(options); afterBuild(options);
return; 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); process.exit(1);
}); });
}); });
...@@ -203,16 +207,18 @@ function testBinary(options) { ...@@ -203,16 +207,18 @@ function testBinary(options) {
return build(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 { try {
require('../').renderSync({ require('../').renderSync({
data: 's { a: ss }' data: 's { a: ss }'
}); });
console.log('Binary is fine; exiting.'); log.info('node-sass build', 'Binary is fine');
} catch (e) { } 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); return build(options);
} }
......
...@@ -48,7 +48,7 @@ function download(url, dest, cb) { ...@@ -48,7 +48,7 @@ function download(url, dest, cb) {
return response.statusCode >= 200 && response.statusCode < 300; 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 { try {
request(url, downloadOptions(), function(err, response) { request(url, downloadOptions(), function(err, response) {
...@@ -57,12 +57,13 @@ function download(url, dest, cb) { ...@@ -57,12 +57,13 @@ function download(url, dest, cb) {
} else if (!successful(response)) { } else if (!successful(response)) {
reportError(['HTTP error', response.statusCode, response.statusMessage].join(' ')); reportError(['HTTP error', response.statusCode, response.statusMessage].join(' '));
} else { } else {
log.http('node-sass install', 'Download complete');
cb(); cb();
} }
}) })
.on('response', function(response) { .on('response', function(response) {
var length = parseInt(response.headers['content-length'], 10); var length = parseInt(response.headers['content-length'], 10);
var progress = log.newItem(url, length); var progress = log.newItem('', length);
if (successful(response)) { if (successful(response)) {
response.pipe(fs.createWriteStream(dest)); response.pipe(fs.createWriteStream(dest));
...@@ -108,7 +109,7 @@ function checkAndDownloadBinary() { ...@@ -108,7 +109,7 @@ function checkAndDownloadBinary() {
return; return;
} }
log.info('node-sass install', 'Binary downloaded and installed at ' + sass.getBinaryPath()); log.info('node-sass install', 'Binary saved at %s', sass.getBinaryPath());
}); });
}); });
} }
......
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