diff options
author | isaacs <i@izs.me> | 2014-05-03 04:36:47 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2014-05-03 04:36:47 +0400 |
commit | ee321aedd6c2077374cde8fa95d08fe3a2d34c42 (patch) | |
tree | 4e556b339a2b7699ddaf2fc3cbabe3dba275603e /lib | |
parent | 912254128d56664e9233b5536bac2c837c7d0650 (diff) |
run-script: Support --parseable and --json
Also, add a test
Diffstat (limited to 'lib')
-rw-r--r-- | lib/run-script.js | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/run-script.js b/lib/run-script.js index 375d6f7df..a53574759 100644 --- a/lib/run-script.js +++ b/lib/run-script.js @@ -87,10 +87,25 @@ function list(cb) { if (er && er.code !== 'ENOENT' && er.code !== 'ENOTDIR') return cb(er) if (er) d = {} var scripts = Object.keys(d.scripts || {}) - console.log() + + if (log.level === "silent") { + return cb(null, scripts) + } + + if (npm.config.get("json")) { + console.log("%j", d.scripts || {}) + return cb(null, scripts) + } + + var s = ":" + var prefix = "" + if (!npm.config.get("parseable")) { + s = "\n " + prefix = " " + console.log("Available scripts in the %s package:", d.name) + } scripts.forEach(function(script) { - console.log(' ', script) - console.log(' ', d.scripts[script]) + console.log(prefix + script + s + d.scripts[script]) }) return cb(null, scripts) }) |