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