2 ;(function () { // wrapper in case we're in module_context mode
4 // windows: running "npm blah" in this folder will invoke WSH, not node.
5 if (typeof WScript !== "undefined") {
6 WScript.echo("npm does not work when run\n"
7 +"with the Windows Scripting Host\n\n"
8 +"'cd' to a different directory,\n"
9 +"or type 'npm.cmd <args>',\n"
10 +"or type 'node npm <args>'.")
18 var log = require("npmlog")
19 log.pause() // will be unpaused when config is loaded.
20 log.info("it worked if it ends with", "ok")
22 var path = require("path")
23 , npm = require("../lib/npm.js")
24 , npmconf = require("../lib/config/core.js")
25 , errorHandler = require("../lib/utils/error-handler.js")
27 , configDefs = npmconf.defs
28 , shorthands = configDefs.shorthands
29 , types = configDefs.types
30 , nopt = require("nopt")
32 // if npm is called as "npmg" or "npm_g", then
33 // run in global mode.
34 if (path.basename(process.argv[1]).slice(-1) === "g") {
35 process.argv.splice(1, 1, "npm", "-g")
38 log.verbose("cli", process.argv)
40 var conf = nopt(types, shorthands)
41 npm.argv = conf.argv.remain
42 if (npm.deref(npm.argv[0])) npm.command = npm.argv.shift()
43 else conf.usage = true
47 console.log(npm.version)
52 npm.command = "version"
57 log.info("using", "npm@%s", npm.version)
58 log.info("using", "node@%s", process.version)
60 process.on("uncaughtException", errorHandler)
62 if (conf.usage && npm.command !== "help") {
63 npm.argv.unshift(npm.command)
67 // now actually fire up npm and run the command.
68 // this is how to use npm programmatically:
70 npm.load(conf, function (er) {
71 if (er) return errorHandler(er)
72 npm.commands[npm.command](npm.argv, errorHandler)