diff options
author | Forrest L Norvell <forrest@npmjs.com> | 2014-11-14 05:11:28 +0300 |
---|---|---|
committer | Forrest L Norvell <forrest@npmjs.com> | 2014-11-14 05:13:53 +0300 |
commit | 27148c03eb4cc4e27ea2fe8b6a9848acf81c470b (patch) | |
tree | b2c7385d57055016d87da188ab2bc62c5666e4e2 /lib/owner.js | |
parent | 93d120cb86f184eb508076bc1c7106517e9236ae (diff) |
terser npm owner output (+ tests)
Diffstat (limited to 'lib/owner.js')
-rw-r--r-- | lib/owner.js | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/lib/owner.js b/lib/owner.js index 53db90f88..315f82eb3 100644 --- a/lib/owner.js +++ b/lib/owner.js @@ -1,4 +1,3 @@ - module.exports = owner owner.usage = "npm owner add <username> <pkg>" @@ -209,17 +208,18 @@ function mutate (pkg, user, mutation, cb) { } // save the number of maintainers before mutation so that we can figure - // out if maintainers were added or removed and print a friendly message - // accordingly + // out if maintainers were added or removed var beforeMutation = data.maintainers.length var m = mutation(u, data.maintainers) if (!m) return cb() // handled if (m instanceof Error) return cb(m) // error - data = { _id : data._id - , _rev : data._rev - , maintainers : m - } + + data = { + _id : data._id, + _rev : data._rev, + maintainers : m + } var dataPath = pkg + "/-rev/" + data._rev mapToRegistry(dataPath, npm.config, function (er, uri, auth) { if (er) return cb(er) @@ -230,24 +230,20 @@ function mutate (pkg, user, mutation, cb) { auth : auth } npm.registry.request(uri, params, function (er, data) { - if (!er && data.error) er = new Error( - "Failed to update package metadata: " + JSON.stringify(data) - ) + if (!er && data.error) { + er = new Error("Failed to update package metadata: "+JSON.stringify(data)) + } + if (er) { log.error("owner mutate", "Failed to update package metadata") } - else { - - // an owner was added - if (m.length > beforeMutation) { - console.log("Added %s as an owner of %s", user, pkg) - } - - // an owner was removed - else if (m.length < beforeMutation) { - console.log("Removed %s as an owner of %s", user, pkg) - } + else if (m.length > beforeMutation) { + console.log("+ %s (%s)", user, pkg) } + else if (m.length < beforeMutation) { + console.log("- %s (%s)", user, pkg) + } + cb(er, data) }) }) |