7 process.title = 'node-gyp'
10 * Module dependencies.
13 var gyp = require('../')
14 var log = require('npmlog')
17 * Process and execute the selected commands.
22 prog.parseArgv(process.argv)
24 if (prog.todo.length === 0) {
25 if (~process.argv.indexOf('-v') || ~process.argv.indexOf('--version')) {
26 console.log('v%s', prog.version)
28 console.log('%s', prog.usage())
30 return process.exit(0)
33 log.info('it worked if it ends with', 'ok')
34 log.verbose('cli', process.argv)
35 log.info('using', 'node-gyp@%s', prog.version)
36 log.info('using', 'node@%s | %s | %s', process.versions.node, process.platform, process.arch)
40 * Change dir if -C/--directory was passed.
43 var dir = prog.opts.directory
45 var fs = require('fs')
47 var stat = fs.statSync(dir)
48 if (stat.isDirectory()) {
49 log.info('chdir', dir)
52 log.warn('chdir', dir + ' is not a directory')
55 if (e.code === 'ENOENT') {
56 log.warn('chdir', dir + ' is not a directory')
58 log.warn('chdir', 'error during chdir() "%s"', e.message)
64 var command = prog.todo.shift()
72 prog.commands[command.name](command.args, function (err) {
74 log.error(command.name + ' error')
75 log.error('stack', err.stack)
78 return process.exit(1)
80 if (command.name == 'list') {
81 var versions = arguments[1]
82 if (versions.length > 0) {
83 versions.forEach(function (version) {
87 console.log('No node development files installed. Use `node-gyp install` to install a version.')
89 } else if (arguments.length >= 2) {
90 console.log.apply(console, [].slice.call(arguments, 1))
93 // now run the next command in the queue
98 process.on('exit', function (code) {
99 if (!completed && !code) {
100 log.error('Completion callback never invoked!')
106 process.on('uncaughtException', function (err) {
107 log.error('UNCAUGHT EXCEPTION')
108 log.error('stack', err.stack)
113 function errorMessage () {
114 // copied from npm's lib/util/error-handler.js
115 var os = require('os')
116 log.error('System', os.type() + ' ' + os.release())
117 log.error('command', process.argv
118 .map(JSON.stringify).join(' '))
119 log.error('cwd', process.cwd())
120 log.error('node -v', process.version)
121 log.error('node-gyp -v', 'v' + prog.package.version)
124 function issueMessage () {
126 log.error('', [ 'This is a bug in `node-gyp`.'
127 , 'Try to update node-gyp and file an Issue if it does not help:'
128 , ' <https://github.com/TooTallNate/node-gyp/issues>'
132 // start running the given commands!