diff options
author | Daijiro Wachi <daijiro.wachi@gmail.com> | 2015-02-26 10:38:44 +0300 |
---|---|---|
committer | Forrest L Norvell <forrest@npmjs.com> | 2015-02-27 09:44:38 +0300 |
commit | a0a87777af8bee180e4e9321699f050c29ed5ac4 (patch) | |
tree | 49053c98ee7e904bda19541ae4aae6f95fab666f /lib | |
parent | d3df7c7847ac51e8b547e4568bdab5aea84fafc4 (diff) |
run-scripts: group scripts in list output
Diffstat (limited to 'lib')
-rw-r--r-- | lib/run-script.js | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/lib/run-script.js b/lib/run-script.js index 92f8d51f2..cb797c7b8 100644 --- a/lib/run-script.js +++ b/lib/run-script.js @@ -84,31 +84,55 @@ 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) } - var s = ":" - var prefix = "" - if (!npm.config.get("parseable")) { - s = "\n " - prefix = " " - console.log("Available scripts in the %s package:", d.name) + if (npm.config.get("parseable")) { + allScripts.forEach(function(script) { + console.log(script + ":" + d.scripts[script]) + }) + return cb(null, allScripts) } + + var s = "\n " + var prefix = " " + var header = "Available scripts in the %s package" + if (scripts.length) console.log(header + ":", 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(header + " with run-scripts:", d.name) + } + else if (runScripts.length) { + console.log("\nwith run-scripts:") + } + runScripts.forEach(function(script) { + console.log(prefix + script + s + d.scripts[script]) + }) + return cb(null, allScripts) }) } |