Permalink
Browse files

add "npm use"

  • Loading branch information...
1 parent ecc18a6 commit 0e60a49fc14aba608685bbcf510fd0c4f72fb3e7 @thejh committed Aug 10, 2011
Showing with 79 additions and 1 deletion.
  1. +35 −0 lib/use.js
  2. +1 −1 lib/utils/npm-registry-client/index.js
  3. +42 −0 lib/utils/npm-registry-client/use.js
  4. +1 −0 npm.js
View
@@ -0,0 +1,35 @@
+
+module.exports = use
+
+var npm = require("../npm")
+ , registry = require("./utils/npm-registry-client")
+ , log = require("./utils/log")
+ , tar = require("./utils/tar")
+ , sha = require("./utils/sha")
+ , path = require("path")
+ , readJson = require("./utils/read-json")
+ , fs = require("fs")
+ , lifecycle = require("./utils/lifecycle")
+ , chain = require("slide").chain
+
+use.usage = "npm use <package> <yes/no>"
+
+use.completion = function (opts, cb) {
+ // for now, not yet implemented.
+ return cb()
+}
+
+function use (args, cb) {
+ if (args.length !== 2) return cb(new Error("you must specify exactly two parameters: package and yes or no"))
+ var using
+ if (args[1] === "yes")
+ using = true
+ else if (args[1] === "no")
+ using = false
+ else
+ return cb(new Error("you must specify exactly one parameter: yes or no"))
+ log.verbose(args, "use")
+ registry.use(args[0], using, function (er) {
+ cb(er)
+ })
+}
@@ -12,5 +12,5 @@ function setLazyGet (p) {
, enumerable : true })
}
-; ["publish", "unpublish", "tag", "adduser", "get", "request"]
+; ["publish", "unpublish", "tag", "adduser", "get", "request", "use"]
.forEach(setLazyGet)
@@ -0,0 +1,42 @@
+
+module.exports = use
+
+var request = require("./request")
+ , GET = request.GET
+ , PUT = request.PUT
+ , DELETE = request.DELETE
+ , reg = request.reg
+ , upload = request.upload
+ , log = require("../log")
+ , path = require("path")
+ , npm = require("../../../npm")
+ , url = require("url")
+
+function use (package, usingValue, cb) {
+ var registry = reg()
+ if (registry instanceof Error) return cb(registry)
+
+ var users = {}
+ users[new Buffer(npm.config.get("_auth"), 'base64').toString().split(':')[0]] = usingValue
+
+ var fullData =
+ { _id : package
+ , name : package
+ , users: users
+ }
+
+ var dataURI = encodeURIComponent(package)
+
+ GET(package, function (er, fullData) {
+ if (er) return cb(er)
+
+ fullData = {
+ users: users
+ , _id: fullData._id
+ , _rev: fullData._rev
+ }
+ return PUT(dataURI, fullData, function (er) {
+ cb(er)
+ })
+ })
+}
View
1 npm.js
@@ -88,6 +88,7 @@ var commandCache = {}
, "link"
, "publish"
+ , "use"
, "tag"
, "adduser"
, "unpublish"

0 comments on commit 0e60a49

Please sign in to comment.