Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMike Sherov <mike.sherov@gmail.com>2017-08-04 23:13:45 +0300
committerKat Marchán <kzm@sykosomatic.org>2017-08-16 03:57:20 +0300
commit80e2f4960691bc5dbd8320002e4d9143784b9ce9 (patch)
tree1da646b27db42d371f31ad95f67e57071e16a42c /lib
parent96d78df9843187bc53be2c93913e8567003ccb73 (diff)
config: provide --json cli switch to npm config list
This will support other CLI tools, notably cipm, that need to query npm for its configuration without having to parse ini format. PR-URL: https://github.com/npm/npm/pull/18025 Credit: @mikesherov Reviewed-By: @zkat
Diffstat (limited to 'lib')
-rw-r--r--lib/config.js21
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/config.js b/lib/config.js
index b4ac74c74..d260c04a5 100644
--- a/lib/config.js
+++ b/lib/config.js
@@ -19,7 +19,7 @@ config.usage = usage(
'npm config set <key> <value>' +
'\nnpm config get [<key>]' +
'\nnpm config delete <key>' +
- '\nnpm config list' +
+ '\nnpm config list [--json]' +
'\nnpm config edit' +
'\nnpm set <key> <value>' +
'\nnpm get [<key>]'
@@ -69,7 +69,7 @@ function config (args, cb) {
return del(args[0], cb)
case 'list':
case 'ls':
- return list(cb)
+ return npm.config.get('json') ? listJson(cb) : list(cb)
case 'edit':
return edit(cb)
default:
@@ -177,6 +177,23 @@ function getKeys (data) {
return Object.keys(data).filter(publicVar).sort(sort)
}
+function listJson (cb) {
+ const publicConf = npm.config.keys.reduce((publicConf, k) => {
+ var value = npm.config.get(k)
+
+ if (publicVar(k) &&
+ // argv is not really config, it's command config
+ k !== 'argv' &&
+ // logstream is a Stream, and would otherwise produce circular refs
+ k !== 'logstream') publicConf[k] = value
+
+ return publicConf
+ }, {})
+
+ output(JSON.stringify(publicConf, null, 2))
+ return cb()
+}
+
function listFromSource (title, conf, long) {
var confKeys = getKeys(conf)
var msg = ''