2 // utilities for working with the js-registry site.
4 module.exports = RegClient
8 , path = require('path')
9 , CouchLogin = require('couch-login')
13 npmlog = require("npmlog")
15 npmlog = { error: noop, warn: noop, info: noop,
16 verbose: noop, silly: noop, http: noop,
17 pause: noop, resume: noop }
22 function RegClient (conf) {
23 // accept either a plain-jane object, or a npmconf object
24 // with a "get" method.
25 if (typeof conf.get !== 'function') {
27 conf = { get: function (k) { return data[k] }
28 , set: function (k, v) { data[k] = v }
29 , del: function (k) { delete data[k] } }
34 // if provided, then the registry needs to be a url.
35 // if it's not provided, then we're just using the cache only.
36 var registry = conf.get('registry')
38 registry = url.parse(registry)
39 if (!registry.protocol) throw new Error(
40 'Invalid registry: ' + registry.url)
41 registry = registry.href
42 if (registry.slice(-1) !== '/') {
45 this.conf.set('registry', registry)
50 if (!conf.get('cache')) throw new Error("Cache dir is required")
52 var auth = this.conf.get('_auth')
53 var alwaysAuth = this.conf.get('always-auth')
54 if (auth && !alwaysAuth && registry) {
55 // if we're always authing, then we just send the
56 // user/pass on every thing. otherwise, create a
57 // session, and use that.
58 var token = this.conf.get('_token')
59 this.couchLogin = new CouchLogin(registry, token)
60 this.couchLogin.proxy = this.conf.get('proxy')
61 this.couchLogin.strictSSL = this.conf.get('strict-ssl')
62 this.couchLogin.ca = this.conf.get('ca')
65 this.log = conf.log || conf.get('log') || npmlog
68 require('fs').readdirSync(__dirname + "/lib").forEach(function (f) {
69 if (!f.match(/\.js$/)) return
70 RegClient.prototype[f.replace(/\.js$/, '')] = require('./lib/' + f)