summaryrefslogtreecommitdiff
path: root/deps/npm/lib/run-script.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/lib/run-script.js')
-rw-r--r--deps/npm/lib/run-script.js49
1 files changed, 38 insertions, 11 deletions
diff --git a/deps/npm/lib/run-script.js b/deps/npm/lib/run-script.js
index ce8ea0f13a..b6aa5fe7e8 100644
--- a/deps/npm/lib/run-script.js
+++ b/deps/npm/lib/run-script.js
@@ -84,31 +84,56 @@ function runScript (args, cb) {
function list(cb) {
var json = path.join(npm.localPrefix, "package.json")
+ var cmdList = [ "publish", "install", "uninstall"
+ , "test", "stop", "start", "restart"
+ ].reduce(function (l, p) {
+ return l.concat(["pre" + p, p, "post" + p])
+ }, [])
return readJson(json, function(er, d) {
if (er && er.code !== "ENOENT" && er.code !== "ENOTDIR") return cb(er)
if (er) d = {}
- var scripts = Object.keys(d.scripts || {})
+ var allScripts = Object.keys(d.scripts || {})
+ var scripts = []
+ var runScripts = []
+ allScripts.forEach(function (script) {
+ if (cmdList.indexOf(script) !== -1) scripts.push(script)
+ else runScripts.push(script)
+ })
if (log.level === "silent") {
- return cb(null, scripts)
+ return cb(null, allScripts)
}
if (npm.config.get("json")) {
console.log(JSON.stringify(d.scripts || {}, null, 2))
- return cb(null, scripts)
+ return cb(null, allScripts)
+ }
+
+ if (npm.config.get("parseable")) {
+ allScripts.forEach(function(script) {
+ console.log(script + ":" + d.scripts[script])
+ })
+ return cb(null, allScripts)
}
- var s = ":"
- var prefix = ""
- if (!npm.config.get("parseable")) {
- s = "\n "
- prefix = " "
- console.log("Available scripts in the %s package:", d.name)
+ var s = "\n "
+ var prefix = " "
+ if (scripts.length) {
+ console.log("Lifecycle scripts included in %s:", d.name)
}
scripts.forEach(function(script) {
console.log(prefix + script + s + d.scripts[script])
})
- return cb(null, scripts)
+ if (!scripts.length && runScripts.length) {
+ console.log("Scripts available in %s via `npm run-script`:", d.name)
+ }
+ else if (runScripts.length) {
+ console.log("\navailable via `npm run-script`:")
+ }
+ runScripts.forEach(function(script) {
+ console.log(prefix + script + s + d.scripts[script])
+ })
+ return cb(null, allScripts)
})
}
@@ -116,7 +141,7 @@ function run (pkg, wd, cmd, args, cb) {
if (!pkg.scripts) pkg.scripts = {}
var cmds
- if (cmd === "restart") {
+ if (cmd === "restart" && !pkg.scripts.restart) {
cmds = [
"prestop", "stop", "poststop",
"restart",
@@ -134,6 +159,8 @@ function run (pkg, wd, cmd, args, cb) {
log.verbose("run-script using default platform env: env (Unix)")
pkg.scripts[cmd] = "env"
}
+ } else if (npm.config.get("if-present")) {
+ return cb(null);
} else {
return cb(new Error("missing script: " + cmd))
}