1 | #!/usr/bin/env node
|
2 | ;(function () {
|
3 |
|
4 |
|
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>'.")
|
11 | WScript.quit(1)
|
12 | return
|
13 | }
|
14 |
|
15 |
|
16 | var log = require("npmlog")
|
17 | log.pause()
|
18 | log.info("it worked if it ends with", "ok")
|
19 |
|
20 | var fs = require("graceful-fs")
|
21 | , path = require("path")
|
22 | , npm = require("../lib/npm.js")
|
23 | , npmconf = require("npmconf")
|
24 | , errorHandler = require("../lib/utils/error-handler.js")
|
25 |
|
26 | , configDefs = npmconf.defs
|
27 | , shorthands = configDefs.shorthands
|
28 | , types = configDefs.types
|
29 | , nopt = require("nopt")
|
30 |
|
31 | process.title = npm.name
|
32 |
|
33 |
|
34 |
|
35 | if (path.basename(process.argv[1]).slice(-1) === "g") {
|
36 | process.argv.splice(1, 1, "npm", "-g")
|
37 | }
|
38 |
|
39 | log.verbose("cli", process.argv)
|
40 |
|
41 | var conf = nopt(types, shorthands)
|
42 | npm.argv = conf.argv.remain
|
43 | if (npm.deref(npm.argv[0])) npm.command = npm.argv.shift()
|
44 | else conf.usage = true
|
45 |
|
46 |
|
47 | if (conf.version) {
|
48 | console.log(npm.version)
|
49 | return
|
50 | }
|
51 |
|
52 | if (conf.versions) {
|
53 | npm.command = "version"
|
54 | conf.usage = false
|
55 | npm.argv = []
|
56 | }
|
57 |
|
58 | log.info("using", npm.name + "@%s", npm.version)
|
59 | log.info("using", "node@%s", process.version)
|
60 |
|
61 |
|
62 | var semver = require("semver")
|
63 | , nodeVer = process.version
|
64 | , reqVer = npm.nodeVersionRequired
|
65 | if (reqVer && !semver.satisfies(nodeVer, reqVer)) {
|
66 | return errorHandler(new Error(
|
67 | "npm doesn't work with node " + nodeVer
|
68 | + "\nRequired: node@" + reqVer), true)
|
69 | }
|
70 |
|
71 | process.on("uncaughtException", errorHandler)
|
72 |
|
73 | if (conf.usage && npm.command !== "help") {
|
74 | npm.argv.unshift(npm.command)
|
75 | npm.command = "help"
|
76 | }
|
77 |
|
78 |
|
79 |
|
80 | conf._exit = true
|
81 | npm.load(conf, function (er) {
|
82 | if (er) return errorHandler(er)
|
83 | npm.commands[npm.command](npm.argv, errorHandler)
|
84 | })
|
85 |
|
86 | })()
|