Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial take at using 'npmlog' for logging

 * adds a '--loglevel' switch to node-gyp which accepts the same values as npm
 * now the '--verbose' flag is simply an alias to '--loglevel=verbose'
 * this simplifies the code a bit, since any logging logic is now removed
 * more log levels! it's mostly verbose() and info() being used
   * still need to go back and move some of logging calls to a better level
  • Loading branch information...
commit 47de81f963632ecb1730e56f41b52d95208468ed 1 parent 4aa0eed
@TooTallNate authored
View
102 bin/node-gyp.js
@@ -11,9 +11,7 @@ process.title = 'node-gyp'
*/
var gyp = require('../')
- , inspect = require('util').inspect
- , ansi = require('ansi')
- , cursor = ansi(process.stderr)
+var log = require('npmlog')
/**
* Process and execute the selected commands.
@@ -26,52 +24,10 @@ if (prog.todo.length === 0) {
return prog.usageAndExit()
}
+log.info('it worked if it ends with', 'ok')
+log.info('using', 'node-gyp@%s', prog.version)
+log.info('using', 'node@%s', process.versions.node)
-/**
- * Set up logging handlers.
- */
-
-prog.on('info', function () {
- cursor.fg.green().write('info ')
- .fg.grey().write(arguments[0] + ' ')
- .reset()
- for (var i=1, l=arguments.length; i<l; i++) {
- cursor.write(arguments[i] + ' ')
- }
- cursor.write('\n')
-})
-
-prog.on('warn', function () {
- cursor.fg.yellow().bg.red().write('warn')
- .fg.reset().bg.reset().write(' ')
- .fg.grey().write(arguments[0])
- .write(' ')
- .reset()
- for (var i=1, l=arguments.length; i<l; i++) {
- cursor.write(arguments[i] + ' ')
- }
- cursor.write('\n')
-})
-
-if (prog.opts.verbose) {
- prog.on('verbose', function () {
- cursor.fg.cyan().write('verb ')
- .fg.grey().write(arguments[0] + ' ')
- .reset()
- for (var i=1, l=arguments.length; i<l; i++) {
- cursor.write(inspect(arguments[i]) + ' ')
- }
- cursor.write('\n')
- })
-}
-
-prog.on('spawn', function (command, args, proc) {
- cursor.fg.magenta().write('spawn ')
- .fg.grey().write(command + ' ')
- .reset().write(inspect(args) + '\n')
-})
-
-prog.info('it worked if it ends with', 'ok')
/**
* Change dir if -C/--directory was passed.
@@ -83,13 +39,17 @@ if (dir) {
try {
var stat = fs.statSync(dir)
if (stat.isDirectory()) {
- prog.info('chdir:', dir)
+ log.info('chdir', dir)
process.chdir(dir)
} else {
- prog.warn(dir + ' is not a directory')
+ log.warn('chdir', dir + ' is not a directory')
}
} catch (e) {
- prog.warn('directory:', e.message)
+ if (e.code === 'ENOENT') {
+ log.warn('chdir', dir + ' is not a directory')
+ } else {
+ log.warn('chdir', 'unknown error during chdir()', e.message)
+ }
}
}
@@ -101,16 +61,14 @@ function run () {
if (prog.todo.length === 0) {
// done!
completed = true
- prog.info('done', 'ok')
+ log.info('done', 'ok')
return
}
var command = prog.todo.shift()
prog.commands[command](prog.argv.slice(), function (err) {
if (err) {
- cursor.fg.red().write('ERR! ')
- .fg.reset().write(err.stack + '\n')
- cursor.fg.red().write('ERR! ')
- .fg.reset().write('not ok\n')
+ log.error(command + ' error', err.stack)
+ log.error('not ok')
return process.exit(1)
}
if (command == 'list') {
@@ -120,39 +78,31 @@ function run () {
console.log(version)
})
} else {
- prog.info('No node development files installed. Use `node-gyp install` to install a version.')
+ console.log('No node development files installed. Use `node-gyp install` to install a version.')
}
} else if (arguments.length >= 2) {
console.log.apply(console, [].slice.call(arguments, 1))
}
+
+ // now run the next command in the queue
process.nextTick(run)
})
}
process.on('exit', function (code) {
if (!completed && !code) {
- cursor.fg.red().write('ERR! ')
- .fg.reset().write('Completion callback never invoked!\n')
- cursor.fg.red().write('ERR! ')
- .fg.reset().write('This is a bug in `node-gyp`. Please open an Issue:\n')
- cursor.fg.red().write('ERR! ')
- .fg.reset().write(' https://github.com/TooTallNate/node-gyp/issues\n')
- cursor.fg.red().write('ERR! ')
- .fg.reset().write('not ok\n')
+ log.error('Completion callback never invoked!')
+ log.error('This is a bug in `node-gyp`, please file an Issue:')
+ log.error('', ' https://github.com/TooTallNate/node-gyp/issues')
+ log.error('not ok')
process.exit(6)
}
})
process.on('uncaughtException', function (err) {
- cursor.fg.red().write('ERR! ')
- .fg.reset().write('UNCAUGHT EXCEPTION:\n')
- cursor.fg.red().write('ERR! ')
- .fg.reset().write(err.stack + '\n')
- cursor.fg.red().write('ERR! ')
- .fg.reset().write('This is a bug in `node-gyp`. Please open an Issue:\n')
- cursor.fg.red().write('ERR! ')
- .fg.reset().write(' https://github.com/TooTallNate/node-gyp/issues\n')
- cursor.fg.red().write('ERR! ')
- .fg.reset().write('not ok\n')
- process.exit(1)
+ log.error('UNCAUGHT EXCEPTION', err.stack)
+ log.error('This is a bug in `node-gyp`, please file an Issue:')
+ log.error('', ' https://github.com/TooTallNate/node-gyp/issues')
+ log.error('not ok')
+ process.exit(7)
})
View
21 lib/build.js
@@ -8,6 +8,7 @@ module.exports = exports = build
var fs = require('graceful-fs')
, path = require('path')
, glob = require('glob')
+ , log = require('npmlog')
, which = require('which')
, mkdirp = require('./util/mkdirp')
, win = process.platform == 'win32'
@@ -17,7 +18,6 @@ exports.usage = 'Invokes `' + (win ? 'msbuild' : 'make') + '` and builds the mod
function build (gyp, argv, callback) {
- gyp.verbose('build args', argv)
var makeCommand = openbsd ? 'gmake' : 'make'
var command = win ? 'msbuild' : makeCommand
, buildDir = path.resolve('build')
@@ -59,9 +59,9 @@ function build (gyp, argv, callback) {
buildType = 'Release'
}
- gyp.verbose('build type:', buildType)
- gyp.verbose('architecture:', arch)
- gyp.verbose('node dev dir:', nodeDir)
+ log.verbose('build type:', buildType)
+ log.verbose('architecture:', arch)
+ log.verbose('node dev dir:', nodeDir)
if (win) {
findSolutionFile()
@@ -82,7 +82,7 @@ function build (gyp, argv, callback) {
return callback(new Error('Could not find *.sln file. Did you run "configure"?'))
}
guessedSolution = files[0]
- gyp.verbose('found first Solution file', guessedSolution)
+ log.verbose('found first Solution file', guessedSolution)
doWhich()
})
}
@@ -104,7 +104,7 @@ function build (gyp, argv, callback) {
}
return
}
- gyp.verbose('`which` succeeded for `' + command + '`', execPath)
+ log.verbose('`which` succeeded for `' + command + '`', execPath)
copyNodeLib()
})
}
@@ -114,7 +114,7 @@ function build (gyp, argv, callback) {
*/
function guessMsbuild () {
- gyp.verbose('could not find "msbuild.exe". guessing location')
+ log.verbose('could not find "msbuild.exe". guessing location')
// This is basically just hard-coded. If this causes problems
// then we'll think of something more clever.
var windir = process.env.WINDIR || process.env.SYSTEMROOT || 'C:\\WINDOWS'
@@ -149,7 +149,7 @@ function build (gyp, argv, callback) {
mkdirp(buildDir, function (err, isNew) {
if (err) return callback(err)
- gyp.verbose('"' + buildType + '" dir needed to be created?', isNew)
+ log.verbose('"' + buildType + '" dir needed to be created?', isNew)
var rs = fs.createReadStream(archNodeLibPath)
, ws = fs.createWriteStream(buildNodeLibPath)
rs.pipe(ws)
@@ -166,10 +166,11 @@ function build (gyp, argv, callback) {
function doBuild () {
// Enable Verbose build
- if (!win && gyp.opts.verbose) {
+ var verbose = log.levels[log.level] <= log.levels.verbose
+ if (!win && verbose) {
argv.push('V=1')
}
- if (win && !gyp.opts.verbose) {
+ if (win && !verbose) {
argv.push('/clp:Verbosity=minimal')
}
View
3  lib/clean.js
@@ -8,6 +8,7 @@ exports.usage = 'Removes any generated build files and the "out" dir'
*/
var rm = require('rimraf')
+var log = require('npmlog')
function clean (gyp, argv, callback) {
@@ -15,7 +16,7 @@ function clean (gyp, argv, callback) {
// Remove the 'build' dir
var buildDir = 'build'
- gyp.verbose('removing "build" directory')
+ log.verbose('clean', 'removing "%s" directory', buildDir)
rm(buildDir, callback)
}
View
35 lib/configure.js
@@ -8,6 +8,7 @@ module.exports = exports = configure
var fs = require('graceful-fs')
, path = require('path')
, glob = require('glob')
+ , log = require('npmlog')
, which = require('which')
, semver = require('semver')
, mkdirp = require('./util/mkdirp')
@@ -26,7 +27,7 @@ function configure (gyp, argv, callback) {
// Make sure that Python is in the $PATH
function checkPython () {
- gyp.verbose('checking for Python executable "' + python + '" in the PATH')
+ log.verbose('check python', 'checking for Python executable "%s" in the PATH', python)
which(python, function (err, execPath) {
if (err) {
if (win) {
@@ -36,7 +37,7 @@ function configure (gyp, argv, callback) {
}
return
}
- gyp.verbose('`which` succeeded for `' + python + '`', execPath)
+ log.verbose('`which` succeeded for `' + python + '`', execPath)
// TODO: ensure compatible Python version
getNodeDir()
})
@@ -45,13 +46,13 @@ function configure (gyp, argv, callback) {
// Called on Windows when "python" isn't available in the current $PATH.
// We're gonna glob C:\python2*
function guessPython () {
- gyp.verbose('could not find "' + python + '". guessing location')
+ log.verbose('could not find "' + python + '". guessing location')
var rootDir = process.env.HOMEDRIVE || process.env.SystemDrive || 'C:\\'
if (rootDir[rootDir.length - 1] !== '\\') {
rootDir += '\\'
}
var pythonPath = path.resolve(rootDir, 'Python27', 'python.exe')
- gyp.verbose('ensuring that file exists:', pythonPath)
+ log.verbose('ensuring that file exists:', pythonPath)
fs.stat(pythonPath, function (err, stat) {
if (err) {
if (err.code == 'ENOENT') {
@@ -87,7 +88,7 @@ function configure (gyp, argv, callback) {
nodeDir = nodeDir.replace(/^~/, process.env.HOME)
}
- gyp.verbose('compiling against specified --nodedir dev files', nodeDir)
+ log.verbose('get node dir', 'compiling against specified --nodedir dev files: %s', nodeDir)
createBuildDir()
} else {
@@ -98,11 +99,11 @@ function configure (gyp, argv, callback) {
if (gyp.opts.target) {
// if --target was given, then determine a target version to compile for
versionStr = gyp.opts.target
- gyp.verbose('compiling against --target node version', versionStr)
+ log.verbose('get node dir', 'compiling against --target node version: %s', versionStr)
} else {
// if no --target was specified then use the current host node version
versionStr = process.version
- gyp.verbose('no --target version specified, falling back to host node version', versionStr)
+ log.verbose('get node dir', 'no --target version specified, falling back to host node version: %s', versionStr)
}
// make sure we have a valid version
@@ -115,7 +116,7 @@ function configure (gyp, argv, callback) {
gyp.opts.ensure = true
gyp.commands.install([ versionStr ], function (err, version) {
if (err) return callback(err)
- gyp.verbose('target node version installed:', version)
+ log.verbose('get node dir', 'target node version installed:', version)
nodeDir = path.resolve(gyp.devDir, version)
createBuildDir()
})
@@ -123,19 +124,21 @@ function configure (gyp, argv, callback) {
}
function createBuildDir () {
- gyp.verbose('attempting to create "build" dir', buildDir)
+ log.verbose('build dir', 'attempting to create "build" dir: %s', buildDir)
mkdirp(buildDir, function (err, isNew) {
if (err) return callback(err)
- gyp.verbose('"build" dir needed to be created?', isNew)
+ log.verbose('build dir', '"build" dir needed to be created?', isNew)
createConfigFile()
})
}
function createConfigFile (err) {
if (err) return callback(err)
- gyp.verbose('creating build/config.gypi file')
- configPath = path.resolve(buildDir, 'config.gypi')
+ var configFilename = 'config.gypi'
+ configPath = path.resolve(buildDir, configFilename)
+
+ log.verbose(configFilename, 'creating config file')
var config = process.config || {}
, defaults = config.target_defaults
@@ -194,10 +197,12 @@ function configure (gyp, argv, callback) {
return v
}
+ log.silly(configFilename, config)
+
// now write out the config.gypi file to the build/ dir
var prefix = '# Do not edit. File was generated by node-gyp\'s "configure" step'
, json = JSON.stringify(config, boolsToString, 2)
- gyp.verbose('writing out config file', configPath)
+ log.verbose(configFilename, 'writing out config file: %s', configPath)
fs.writeFile(configPath, [prefix, json, ''].join('\n'), runGypAddon)
}
@@ -209,11 +214,11 @@ function configure (gyp, argv, callback) {
if (!~argv.indexOf('-f') && !~argv.indexOf('--format')) {
if (win) {
- gyp.verbose('gyp format was not specified; forcing "msvs"')
+ log.verbose('gyp_addon', 'gyp format was not specified; forcing "msvs"')
// force the 'make' target for non-Windows
argv.push('-f', 'msvs')
} else {
- gyp.verbose('gyp format was not specified; forcing "make"')
+ log.verbose('gyp_addon', 'gyp format was not specified; forcing "make"')
// force the 'make' target for non-Windows
argv.push('-f', 'make')
}
View
69 lib/install.js
@@ -12,6 +12,7 @@ var fs = require('graceful-fs')
, rm = require('rimraf')
, path = require('path')
, zlib = require('zlib')
+ , log = require('npmlog')
, semver = require('semver')
, fstream = require('fstream')
, request = require('request')
@@ -27,7 +28,7 @@ function install (gyp, argv, callback) {
if (cb.done) return
cb.done = true
if (err) {
- gyp.verbose('got an error, rolling back install')
+ log.warn('install', 'got an error, rolling back install')
// roll-back the install if anything went wrong
gyp.commands.remove([ version ], function (err2) {
callback(err)
@@ -40,7 +41,7 @@ function install (gyp, argv, callback) {
// Determine which node dev files version we are installing
var versionStr = argv[0] || gyp.opts.target || process.version
- gyp.verbose('input version string', versionStr)
+ log.verbose('install', 'input version string', versionStr)
// parse the version to normalize and ensure it's valid
var version = semver.parse(versionStr)
@@ -50,7 +51,7 @@ function install (gyp, argv, callback) {
// "legacy" versions are 0.7 and 0.6
var isLegacy = semver.lt(versionStr, '0.8.0')
- gyp.verbose('installing legacy version?', isLegacy)
+ log.verbose('installing legacy version?', isLegacy)
if (semver.lt(versionStr, '0.6.0')) {
return callback(new Error('Minimum target version is `0.6.0` or greater. Got: ' + versionStr))
@@ -60,12 +61,12 @@ function install (gyp, argv, callback) {
if (version[5] === '-pre') {
version[3] = +version[3] - 1
version[5] = null
- gyp.verbose('-pre version detected, adjusting patch version')
+ log.verbose('-pre version detected, adjusting patch version')
}
// flatten version into String
version = version.slice(1, 4).join('.')
- gyp.verbose('installing version', version)
+ log.verbose('install', 'installing version: %s', version)
// the directory where the dev files will be installed
var devDir = path.resolve(gyp.devDir, version)
@@ -73,31 +74,31 @@ function install (gyp, argv, callback) {
// If '--ensure' was passed, then don't *always* install the version;
// check if it is already installed, and only install when needed
if (gyp.opts.ensure) {
- gyp.verbose('--ensure was passed, so won\'t reinstall if already installed')
+ log.verbose('install', '--ensure was passed, so won\'t reinstall if already installed')
fs.stat(devDir, function (err, stat) {
if (err) {
if (err.code == 'ENOENT') {
- gyp.verbose('version not already installed, continuing with install', version)
+ log.verbose('install', 'version not already installed, continuing with install', version)
go()
} else {
cb(err)
}
return
}
- gyp.verbose('version is already installed, need to check "installVersion"')
+ log.verbose('install', 'version is already installed, need to check "installVersion"')
var installVersionFile = path.resolve(devDir, 'installVersion')
fs.readFile(installVersionFile, 'ascii', function (err, ver) {
if (err && err.code != 'ENOENT') {
return cb(err)
}
var installVersion = parseInt(ver, 10) || 0
- gyp.verbose('got "installVersion":', installVersion)
- gyp.verbose('needs "installVersion":', gyp.package.installVersion)
+ log.verbose('got "installVersion":', installVersion)
+ log.verbose('needs "installVersion":', gyp.package.installVersion)
if (installVersion < gyp.package.installVersion) {
- gyp.verbose('version is no good; reinstalling')
+ log.verbose('install', 'version is no good; reinstalling')
go()
} else {
- gyp.verbose('version is good')
+ log.verbose('install', 'version is good')
cb()
}
})
@@ -107,7 +108,8 @@ function install (gyp, argv, callback) {
}
function download (url, onError) {
- gyp.info('downloading:', url)
+ log.http('GET', url)
+
var requestOpts = {
uri: url
, onResponse: true
@@ -119,7 +121,7 @@ function install (gyp, argv, callback) {
|| process.env.HTTP_PROXY
|| process.env.npm_config_proxy
if (proxyUrl) {
- gyp.verbose('using proxy:', proxyUrl)
+ log.http('proxy', proxyUrl)
requestOpts.proxy = proxyUrl
}
return request(requestOpts, onError)
@@ -131,11 +133,7 @@ function install (gyp, argv, callback) {
mkdir(devDir, function (err, created) {
if (err) return cb(err)
- if (created) {
- gyp.verbose('created:', devDir)
- } else {
- gyp.verbose('directory already existed:', devDir)
- }
+ log.verbose('nodedir "%s"', devDir, created)
// now download the node tarball
var tarballUrl = distUrl + '/v' + version + '/node-v' + version + '.tar.gz'
@@ -148,16 +146,17 @@ function install (gyp, argv, callback) {
// only .h header files and the gyp files get extracted
function isValid () {
var name = this.path.substring(devDir.length + 1)
- , _valid = valid(name)
+ var isValid = valid(name)
if (name === '' && this.type === 'Directory') {
// the first directory entry is ok
return true
}
- if (_valid) {
- gyp.verbose('extracted file from tarball', name)
+ if (isValid) {
+ log.verbose('tarball', 'extracted file from tarball:', name)
extractCount++
} else {
// invalid
+ log.silly('tarball', 'ignoring from tarball:', name)
}
return _valid
}
@@ -185,7 +184,7 @@ function install (gyp, argv, callback) {
if (extractCount === 0) {
return cb(new Error('There was a fatal problem while downloading/extracting the tarball'))
}
- gyp.verbose('done parsing tarball')
+ log.verbose('tarball', 'done parsing tarball')
var async = 0
if (isLegacy) {
@@ -219,17 +218,17 @@ function install (gyp, argv, callback) {
function copyLegacy (done) {
// legacy versions of node (< 0.8) require the legacy files to be copied
// over since they contain many bugfixes from the current node build system
- gyp.verbose('copying "legacy" gyp configuration files for version', version)
+ log.verbose('legacy', 'copying "legacy" gyp configuration files for version', version)
var legacyDir = path.resolve(__dirname, '..', 'legacy')
- gyp.verbose('using "legacy" dir', legacyDir)
- gyp.verbose('copying to "dev" dir', devDir)
+ log.verbose('legacy', 'using "legacy" dir', legacyDir)
+ log.verbose('legacy', 'copying to "dev" dir', devDir)
var reader = fstream.Reader({ path: legacyDir, type: 'Directory' })
- , writer = fstream.Writer({ path: devDir, type: 'Directory' })
+ var writer = fstream.Writer({ path: devDir, type: 'Directory' })
reader.on('entry', function onEntry (entry) {
- gyp.verbose('reading entry', entry.path)
+ log.verbose('legacy', 'reading entry:', entry.path)
entry.on('entry', onEntry)
})
@@ -243,7 +242,7 @@ function install (gyp, argv, callback) {
}
function downloadNodeLib (done) {
- gyp.verbose('on Windows; need to download `node.lib`...')
+ log.verbose('on Windows; need to download `node.lib`...')
var dir32 = path.resolve(devDir, 'ia32')
, dir64 = path.resolve(devDir, 'x64')
, nodeLibPath32 = path.resolve(dir32, 'node.lib')
@@ -251,15 +250,15 @@ function install (gyp, argv, callback) {
, nodeLibUrl32 = distUrl + '/v' + version + '/node.lib'
, nodeLibUrl64 = distUrl + '/v' + version + '/x64/node.lib'
- gyp.verbose('32-bit node.lib dir', dir32)
- gyp.verbose('64-bit node.lib dir', dir64)
- gyp.verbose('`node.lib` 32-bit url', nodeLibUrl32)
- gyp.verbose('`node.lib` 64-bit url', nodeLibUrl64)
+ log.verbose('32-bit node.lib dir', dir32)
+ log.verbose('64-bit node.lib dir', dir64)
+ log.verbose('`node.lib` 32-bit url', nodeLibUrl32)
+ log.verbose('`node.lib` 64-bit url', nodeLibUrl64)
var async = 2
mkdir(dir32, function (err) {
if (err) return done(err)
- gyp.verbose('streaming 32-bit node.lib to:', nodeLibPath32)
+ log.verbose('streaming 32-bit node.lib to:', nodeLibPath32)
var req = download(nodeLibUrl32)
req.on('error', done)
@@ -278,7 +277,7 @@ function install (gyp, argv, callback) {
})
mkdir(dir64, function (err) {
if (err) return done(err)
- gyp.verbose('streaming 64-bit node.lib to:', nodeLibPath64)
+ log.verbose('streaming 64-bit node.lib to:', nodeLibPath64)
var req = download(nodeLibUrl64)
req.on('error', done)
View
8 lib/list.js
@@ -9,13 +9,15 @@ exports.usage = 'Prints a listing of the currently installed node development fi
var fs = require('graceful-fs')
, path = require('path')
+ , log = require('npmlog')
function list (gyp, args, callback) {
- gyp.verbose('using node-gyp dir', gyp.devDir)
+ var devDir = gyp.devDir
+ log.verbose('list', 'using node-gyp dir:', devDir)
- // readdir the node-gyp dir
- fs.readdir(gyp.devDir, onreaddir)
+ // readdir() the node-gyp dir
+ fs.readdir(devDir, onreaddir)
function onreaddir (err, versions) {
if (err && err.code != 'ENOENT') {
View
39 lib/node-gyp.js
@@ -8,6 +8,7 @@ module.exports = exports = gyp
var fs = require('graceful-fs')
, path = require('path')
, nopt = require('nopt')
+ , log = require('npmlog')
, child_process = require('child_process')
, EE = require('events').EventEmitter
, inherits = require('util').inherits
@@ -39,7 +40,7 @@ function Gyp () {
var self = this
// set the dir where node-gyp dev files get installed
- // TODO: make this configurable?
+ // TODO: make this *more* configurable?
// see: https://github.com/TooTallNate/node-gyp/issues/21
var homeDir = process.env.HOME || process.env.USERPROFILE
this.devDir = path.resolve(homeDir, '.node-gyp')
@@ -48,7 +49,7 @@ function Gyp () {
commands.forEach(function (command) {
self.commands[command] = function (argv, callback) {
- self.verbose('command', command, argv)
+ log.verbose('command', command, argv)
return require('./' + command)(self, argv, callback)
}
})
@@ -78,10 +79,10 @@ proto.configDefs = {
, directory: String // bin
, msvs_version: String // 'configure'
, ensure: Boolean // 'install'
- , verbose: Boolean // everywhere
, solution: String // 'build' (windows only)
, proxy: String // 'install'
, nodedir: String // 'configure'
+ , loglevel: String // everywhere
}
/**
@@ -92,6 +93,8 @@ proto.shorthands = {
release: '--no-debug'
, C: '--directory'
, d: '--debug'
+ , v: '--loglevel=verbose'
+ , verbose: '--loglevel=verbose'
}
/**
@@ -119,10 +122,7 @@ proto.parseArgv = function parseOpts (argv) {
if (name.indexOf(npm_config_prefix) !== 0) return
var val = process.env[name]
if (name === npm_config_prefix + 'loglevel') {
- // "loglevel" is a special case; check for "verbose"
- if (val === 'verbose') {
- this.opts.verbose = true
- }
+ log.level = val
} else {
// take the config name and check if it's one that node-gyp cares about
name = name.substring(npm_config_prefix.length)
@@ -131,6 +131,11 @@ proto.parseArgv = function parseOpts (argv) {
}
}
}, this)
+
+ if (this.opts.loglevel) {
+ log.level = this.opts.loglevel
+ }
+ log.resume()
}
/**
@@ -148,26 +153,9 @@ proto.spawn = function spawn (command, args, opts) {
}
/**
- * Logging mechanisms.
+ * Prints the usage instructions and then exits.
*/
-proto.info = function info () {
- var args = Array.prototype.slice.call(arguments)
- args.unshift('info')
- this.emit.apply(this, args)
-}
-proto.warn = function warn () {
- var args = Array.prototype.slice.call(arguments)
- args.unshift('warn')
- this.emit.apply(this, args)
-}
-
-proto.verbose = function verbose () {
- var args = Array.prototype.slice.call(arguments)
- args.unshift('verbose')
- this.emit.apply(this, args)
-}
-
proto.usageAndExit = function usageAndExit () {
var usage = [
''
@@ -182,6 +170,7 @@ proto.usageAndExit = function usageAndExit () {
, ' $ node-gyp <command> --help'
, ''
, 'node-gyp@' + this.version + ' ' + path.resolve(__dirname, '..')
+ , 'node@' + process.versions.node
].join('\n')
console.log(usage)
View
4 lib/rebuild.js
@@ -3,13 +3,15 @@ module.exports = exports = rebuild
exports.usage = 'Runs "clean", "configure" and "build" all at once'
+var log = require('npmlog')
+
function rebuild (gyp, argv, callback) {
// first "clean"
gyp.commands.clean([], function (err) {
if (err) {
// don't bail
- gyp.info(err.stack);
+ log.info('rebuild clean failed', err.stack);
}
gyp.commands.configure([], function (err) {
View
10 lib/remove.js
@@ -10,14 +10,17 @@ exports.usage = 'Removes the node development files for the specified version'
var fs = require('fs')
, rm = require('rimraf')
, path = require('path')
+ , log = require('npmlog')
, semver = require('semver')
function remove (gyp, argv, callback) {
- gyp.verbose('using node-gyp dir', gyp.devDir)
+ var devDir = gyp.devDir
+ log.verbose('remove', 'using node-gyp dir:', devDir)
// get the user-specified version to remove
var v = argv[0] || gyp.opts.target
+ log.verbose('remove', 'removing target version:', v)
if (!v) {
return callback(new Error('You must specify a version number to remove. Ex: "' + process.version + '"'))
@@ -34,14 +37,13 @@ function remove (gyp, argv, callback) {
version = version.slice(1, 4).join('.')
var versionPath = path.resolve(gyp.devDir, version)
- gyp.verbose('removing development files for version', version)
+ log.verbose('remove', 'removing development files for version:', version)
// first check if its even installed
fs.stat(versionPath, function (err, stat) {
if (err) {
if (err.code == 'ENOENT') {
- gyp.info('version was already not installed', version)
- callback()
+ callback(null, 'version was already installed: ' + version)
} else {
callback(err)
}
Please sign in to comment.
Something went wrong with that request. Please try again.