1 | 'use strict';
|
2 |
|
3 | var debug = require('debug')('npmjs')
|
4 | , mana = require('mana');
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | var Registry = mana.extend({
|
25 | |
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | initialise: function initialise(options) {
|
32 | options = options || {};
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | var mirrors = Object.keys(Registry.mirrors).map(function map(mirror) {
|
38 | return Registry.mirrors[mirror];
|
39 | });
|
40 |
|
41 | options.registry = 'registry' in options ? options.registry : Registry.mirrors.nodejitsu;
|
42 | options.mirrors = 'mirrors' in options ? options.mirrors : mirrors;
|
43 | options.maxdelay = 'maxdelay' in options ? options.maxdelay : 60000;
|
44 | options.mindelay = 'mindelay' in options ? options.mindelay : 100;
|
45 | options.githulk = 'githulk' in options ? options.githulk : null;
|
46 | options.retries = 'retries' in options ? options.retries : 3;
|
47 | options.factor = 'factor' in options ? options.factor : 2;
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 | if ('string' !== typeof options.registry) options.registry = options.registry.url;
|
55 |
|
56 | this.authorization = options.authorization;
|
57 | this.mirrors = options.mirrors;
|
58 | this.mindelay = options.mindelay;
|
59 | this.maxdelay = options.maxdelay;
|
60 | this.githulk = options.githulk;
|
61 | this.retries = options.retries;
|
62 | this.factor = options.factor;
|
63 | this.api = options.registry;
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 | if (!this.authorization && options.user && options.password) {
|
70 | debug('received authorization information for %s', options.user);
|
71 | this.authorization = new Buffer(
|
72 | options.user +':'+ options.password
|
73 | ).toString('base64');
|
74 | }
|
75 |
|
76 | if (Buffer.isBuffer(this.authorization)) {
|
77 | this.authorization = 'Basic '+ this.authorization;
|
78 | }
|
79 | },
|
80 |
|
81 | |
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 | map: {
|
88 | simple: function simple(data) {
|
89 | return {
|
90 | name: data[1],
|
91 | description: data[2]
|
92 | };
|
93 | }
|
94 | }
|
95 | });
|
96 |
|
97 |
|
98 |
|
99 |
|
100 | Registry.mirrors = {
|
101 | nodejitsu: 'http://registry.nodejitsu.com/',
|
102 | strongloop: 'http://npm.strongloop.com/',
|
103 | npmjsau: 'http://registry.npmjs.org.au/',
|
104 | npmjseu: 'http://registry.npmjs.eu/',
|
105 | npmjspt: 'http://registry.npmjs.pt/',
|
106 | npmjs: 'http://registry.npmjs.org/',
|
107 | cnpmjs: 'http://registry.cnpmjs.org/'
|
108 | };
|
109 |
|
110 |
|
111 |
|
112 |
|
113 | Registry.drink(module);
|