1 // utilities for working with the js-registry site.
3 module.exports = RegClient
5 var join = require('path').join
6 var fs = require('graceful-fs')
10 npmlog = require('npmlog')
26 function RegClient (config) {
27 this.config = Object.create(config || {})
29 this.config.proxy = this.config.proxy || {}
30 if (!this.config.proxy.https && this.config.proxy.http) {
31 this.config.proxy.https = this.config.proxy.http
34 this.config.ssl = this.config.ssl || {}
35 if (this.config.ssl.strict === undefined) this.config.ssl.strict = true
37 this.config.retry = this.config.retry || {}
38 if (typeof this.config.retry.retries !== 'number') this.config.retry.retries = 2
39 if (typeof this.config.retry.factor !== 'number') this.config.retry.factor = 10
40 if (typeof this.config.retry.minTimeout !== 'number') this.config.retry.minTimeout = 10000
41 if (typeof this.config.retry.maxTimeout !== 'number') this.config.retry.maxTimeout = 60000
42 if (typeof this.config.maxSockets !== 'number') this.config.maxSockets = 50
44 this.config.userAgent = this.config.userAgent || 'node/' + process.version
45 this.config.defaultTag = this.config.defaultTag || 'latest'
47 this.log = this.config.log || npmlog
48 delete this.config.log
51 fs.readdirSync(join(__dirname, 'lib')).forEach(function (f) {
52 var entry = join(__dirname, 'lib', f)
54 // lib/group-name/operation.js -> client.groupName.operation
55 var stat = fs.statSync(entry)
56 if (stat.isDirectory()) {
57 var groupName = f.replace(/-([a-z])/, dashToCamel)
58 fs.readdirSync(entry).forEach(function (f) {
59 if (!f.match(/\.js$/)) return
61 if (!client[groupName]) {
62 // keep client.groupName.operation from stomping client.operation
63 client[groupName] = Object.create(client)
65 var name = f.replace(/\.js$/, '').replace(/-([a-z])/, dashToCamel)
66 client[groupName][name] = require(join(entry, f))
71 if (!f.match(/\.js$/)) return
72 var name = f.replace(/\.js$/, '').replace(/-([a-z])/, dashToCamel)
73 client[name] = require(entry)
77 function dashToCamel (_, l) {
78 return l.toUpperCase()