forked from ritthisakdi/npm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
npm-cli.js
executable file
·79 lines (63 loc) · 2 KB
/
npm-cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env node
;(function () { // wrapper in case we're in module_context mode
// windows: running "npm blah" in this folder will invoke WSH, not node.
/*global WScript*/
if (typeof WScript !== 'undefined') {
WScript.echo(
'npm does not work when run\n' +
'with the Windows Scripting Host\n\n' +
"'cd' to a different directory,\n" +
"or type 'npm.cmd <args>',\n" +
"or type 'node npm <args>'."
)
WScript.quit(1)
return
}
process.title = 'npm'
var log = require('npmlog')
log.pause() // will be unpaused when config is loaded.
log.enableProgress()
log.info('it worked if it ends with', 'ok')
var path = require('path')
var npm = require('../lib/npm.js')
var npmconf = require('../lib/config/core.js')
var errorHandler = require('../lib/utils/error-handler.js')
var configDefs = npmconf.defs
var shorthands = configDefs.shorthands
var types = configDefs.types
var nopt = require('nopt')
// if npm is called as "npmg" or "npm_g", then
// run in global mode.
if (path.basename(process.argv[1]).slice(-1) === 'g') {
process.argv.splice(1, 1, 'npm', '-g')
}
log.verbose('cli', process.argv)
var conf = nopt(types, shorthands)
npm.argv = conf.argv.remain
if (npm.deref(npm.argv[0])) npm.command = npm.argv.shift()
else conf.usage = true
if (conf.version) {
console.log(npm.version)
return
}
if (conf.versions) {
npm.command = 'version'
conf.usage = false
npm.argv = []
}
log.info('using', 'npm@%s', npm.version)
log.info('using', 'node@%s', process.version)
process.on('uncaughtException', errorHandler)
if (conf.usage && npm.command !== 'help') {
npm.argv.unshift(npm.command)
npm.command = 'help'
}
// now actually fire up npm and run the command.
// this is how to use npm programmatically:
conf._exit = true
npm.load(conf, function (er) {
if (er) return errorHandler(er)
log.enableProgress()
npm.commands[npm.command](npm.argv, errorHandler)
})
})()