Appearance
Cnpmjs.org_zH
有兴趣的小伙伴可以自己看看呀,针对重要的地方进行了翻译。
javascript
'use strict';
var mkdirp = require('mkdirp');
var copy = require('copy-to');
var path = require('path');
var fs = require('fs');
var os = require('os');
var utility = require('utility');
var version = require('../package.json').version;
var root = path.dirname(__dirname);
var dataDir = path.join(process.env.HOME || root, '.cnpmjs.org');
var config = {
version: version,
dataDir: dataDir,
/**
* Cluster mode 集群模式
*/
enableCluster: false, //是否启用 cluster-worker 模式启动服务,默认 false,生产环节推荐为 true;
numCPUs: os.cpus().length,
/*
* server configure 服务器配置
*/
registryPort: 7001, //仓库访问端口(执行发布安装的网址)
webPort: 7002, //展示查询站点访问端口(可视化页面的查询)
bindingHost: '127.0.0.1', // only binding on 127.0.0.1 for local access 监听绑定的 Host,默认127.0.0.1,外网访问注释掉此项即可
// default is ctx.protocol
protocol: '',
// debug mode 调试模式
// if in debug mode, some middleware like limit wont load 如果在调试模式下,某些中间件如限制负载
// logger module will print to stdout 日志模块打印出来
debug: process.env.NODE_ENV === 'development',
// page mode, enable on development env
pagemock: process.env.NODE_ENV === 'development',
// session secret
sessionSecret: 'cnpmjs.org test session secret',
// max request json body size
jsonLimit: '10mb',
// log dir name 日志目录
logdir: path.join(dataDir, 'logs'),
// update file template dir 临时上传文件
uploadDir: path.join(dataDir, 'downloads'),
// web page viewCache 视图模板缓存是否开启,默认是false
viewCache: false,
// registry http response cache control header
// if you are using CDN, can set it to 'max-age=0, s-maxage=10, must-revalidate'
// it meaning cache 10s on CDN server and no cache on client side.
registryCacheControlHeader: '',
// if you are using CDN, can set it to 'Accept, Accept-Encoding'
registryVaryHeader: '',
// disable package search
disableSearch: false,
// view files directory
viewDir: path.join(root, 'view', 'web'),
customRegistryMiddlewares: [],
customWebMiddlewares: [],
// config for koa-limit middleware
// for limit download rates
limit: {
enable: false,
token: 'koa-limit:download',
limit: 1000,
interval: 1000 * 60 * 60 * 24,
whiteList: [],
blackList: [],
message: 'request frequency limited, any question, please contact fengmk2@gmail.com',
},
enableCompress: false, // enable gzip response or not 是否开启 gzip 压缩,默认为 false
// default system admins 默认系统管理员
admins: {
// name: email
fengmk2: 'fengmk2@gmail.com',
admin: 'admin@cnpmjs.org',
dead_horse: 'dead_horse@qq.com',
},
// email notification for errors 错误时会用电子邮件通知
// check https://github.com/andris9/Nodemailer for more informations
mail: {
enable: false,
appname: 'cnpmjs.org',
from: 'cnpmjs.org mail sender <adderss@gmail.com>',
service: 'gmail',
auth: {
user: 'address@gmail.com',
pass: 'your password'
}
},
logoURL: 'https://os.alipayobjects.com/rmsportal/oygxuIUkkrRccUz.jpg', // cnpm logo image url
adBanner: '',
customReadmeFile: '', // you can use your custom readme file instead the cnpm one
customFooter: '', // you can add copyright and site total script html here
npmClientName: 'cnpm', // use `${name} install package`
packagePageContributorSearch: true, // package page contributor link to search, default is true
// max handle number of package.json `dependencies` property
maxDependencies: 200,
// backup filepath prefix
backupFilePrefix: '/cnpm/backup/',
/**
* database config 数据库配置
*/
database: {
db: 'cnpmjs_test', //数据库名称
username: 'root', //数据库访问账号
password: '', //数据库访问密码
// the sql dialect of the database //使用数据库,默认sqlite
// - currently supported: 'mysql', 'sqlite', 'postgres', 'mariadb'
dialect: 'sqlite',
// custom host; default: 127.0.0.1 数据库访问IP,通常127.0.0.1
host: '127.0.0.1',
// custom port; default: 3306
port: 3306, //数据库访问端口,通常3306
// use pooling in order to reduce db connection overload and to increase speed
// currently only for mysql and postgresql (since v1.5.0)
pool: { //数据库连接池相关配置,为一个对象;
maxConnections: 10, //最大连接数,默认为 10
minConnections: 0, //最小连接数,默认为 0
maxIdleTime: 30000 //单条链接最大空闲时间,默认为 30000 毫秒
},
dialectOptions: {
// if your server run on full cpu load, please set trace to false 如果您的服务器在满cpu负载下运行,请将trace设置为false
trace: true,
},
//仅对 SQLite 配置有效,数据库地址,默认为 ~/.cnpmjs/data.sqlite
// the storage engine for 'sqlite'
// default store into ~/.cnpmjs.org/data.sqlite
storage: path.join(dataDir, 'data.sqlite'),
logging: !!process.env.SQL_DEBUG,
},
// enable proxy npm audits request or not
enableNpmAuditsProxy: true,
//包文件系统处理对象,为一个 Node.js 对象,默认是 fs-cnpm 这个包,并且配置在 ~/.cnpmjs/nfs 目录下,也就是说默认所有同步的包都会被放在这个目录下
// package tarball store in local filesystem by default 默认情况下,包存储在本地文件系统中
nfs: require('fs-cnpm')({
dir: path.join(dataDir, 'nfs')
}),
// if set true, will 302 redirect to `nfs.url(dist.key)`
downloadRedirectToNFS: false,
// don't check database and just download tgz from nfs
downloadTgzDontCheckModule: false,
// remove original tarball when publishing
unpublishRemoveTarball: true,
// registry url name
registryHost: 'r.cnpmjs.org',
/**
* registry mode config 私有模块发布相关配置
*/
// enable private mode or not 是否开启私有模式,默认为 false
// private mode: only admins can publish, other users just can sync package from source npm 私有模式下只有管理员能发布模块,其他账号只有同步权限
// public mode: all users can publish 非私有模式,注册用户都可以发布模块
enablePrivate: false,
//非管理员发布包的时候只能用以 scopes 里面列举的命名空间为前缀来发布,如果没有设置就无法发布,也就是说这是一个必填项,默认为 [ '@cnpm', '@cnpmtest', '@cnpm-test' ],据苏千大大解释是为了便于管理以及让公司的员工自觉按需发布;更多关于 NPM scope 的说明请参见 npm-scope
// registry scopes, if don't set, means do not support scopes
scopes: [ '@cnpm', '@cnpmtest', '@cnpm-test' ],
// some registry already have some private packages in global scope 某些注册表在全局范围内已经有一些私有包
// but we want to treat them as scoped private packages, 但我们希望将它们视为作用域私有包
// so you can use this white list. 所以可以用这个白名单
//出于历史包袱的原因,有些已经存在的私有包(可能之前是用 Git 的方式安装的)并没有以命名空间的形式来命名,而这种包本来是无法上传到 CNPM 的,这个配置项数组就是用来加这些例外白名单的,默认为一个空数组
privatePackages: [],
/**
* sync configs 同步源仓库相关设置
*/
// the official npm registry npm官方注册
// cnpm wont directly sync from this one cnpm不会直接从这个地址同步模块
// but sometimes will request it for some package infomations 但有时会要求它提供一些package信息
// please don't change it if not necessary 如果没有必要性的话,请不要更改
officialNpmRegistry: 'https://registry.npmjs.com',
officialNpmReplicate: 'https://replicate.npmjs.com',
cnpmRegistry: 'https://r.cnpmjs.com',
// sync source, upstream registry 同步源,上游注册表
// If you want to directly sync from official npm's registry 如果你想直接从官方npm的注册表同步
// please drop them an email first 首先给他们发邮件
sourceNpmRegistry: 'https://registry.npm.taobao.org',
sourceNpmWeb: 'https://npm.taobao.org',
// upstream registry is base on cnpm/cnpmjs.org or not 上游registry是否是cnpm,默认true
// if your upstream is official npm registry, please turn it off 若要使用npm官方地址作为同步上游,请设置为false
sourceNpmRegistryIsCNpm: true,
// if install return 404, try to sync from source registry 若安装时模块不存在,是否向源registry进行同步,默认true
syncByInstall: true,
// sync mode select 同步模式选项
// none: do not sync any module, proxy all public modules from sourceNpmRegistry
//none: 不进行同步,只管理用户上传的私有模块,公共模块直接从上游获取
// exist: only sync exist modules
//exist: 只同步已经存在于数据库的模块
// all: sync all modules
//all: 定时同步所有源registry的模块
syncModel: 'none', // 'none', 'all', 'exist'
syncConcurrency: 1,
// sync interval, default is 10 minutes 同步时间间隔,默认10分钟
syncInterval: '10m',
// sync polular modules, default to false
// because cnpm can't auto sync tag change for now
// so we want to sync popular modules to ensure their tags
syncPopular: false,
syncPopularInterval: '1h',
// top 100
topPopular: 100,
// sync devDependencies or not, default is false 是否同步devDependencies,默认值为fals
syncDevDependencies: false,
// try to remove all deleted versions from original registry 尽量从原始注册表中删除所有已删除的版本
syncDeletedVersions: true,
// changes streaming sync
syncChangesStream: false,
syncDownloadOptions: {
// formatRedirectUrl: function (url, location)
},
handleSyncRegistry: 'http://127.0.0.1:7001',
// default badge subject
badgeSubject: 'cnpm', //包的 badge 显示的名字,默认为 cnpm
// defautl use https://badgen.net/
badgeService: {
url: function(subject, status, options) {
options = options || {};
let url = `https://badgen.net/badge/${utility.encodeURIComponent(subject)}/${utility.encodeURIComponent(status)}`;
if (options.color) {
url += `/${utility.encodeURIComponent(options.color)}`;
}
if (options.icon) {
url += `?icon=${utility.encodeURIComponent(options.icon)}`;
}
return url;
},
},
packagephobiaURL: 'https://packagephobia.now.sh',
packagephobiaSupportPrivatePackage: false,
packagephobiaMinDownloadCount: 1000,
// custom user service, @see https://github.com/cnpm/cnpmjs.org/wiki/Use-Your-Own-User-Authorization
// when you not intend to ingegrate with your company's user system, then use null, it would
// use the default cnpm user system
//用户账号系统接入,可以扩展接入公司的账号系统
userService: null,
// always-auth https://docs.npmjs.com/misc/config#always-auth
// Force npm to always require authentication when accessing the registry, even for GET requests.
//是否始终需要用户验证,即便是 $ cnpm install 等命令
alwaysAuth: false,
// if you're behind firewall, need to request through http proxy, please set this
// e.g.: `httpProxy: 'http://proxy.mycompany.com:8080'
//代理地址设置,用于你在墙内源站在墙外的情况
httpProxy: null,
// snyk.io root url
snykUrl: 'https://snyk.io',
// https://github.com/cnpm/cnpmjs.org/issues/1149
// if enable this option, must create module_abbreviated and package_readme table in database
enableAbbreviatedMetadata: false,
// global hook function: function* (envelope) {}
// envelope format please see https://github.com/npm/registry/blob/master/docs/hooks/hooks-payload.md#payload
globalHook: null,
opensearch: {
host: '',
},
// redis cache
redisCache: {
enable: false,
connectOptions: null,
},
};
if (process.env.NODE_ENV === 'test') {
config.enableAbbreviatedMetadata = true;
config.customRegistryMiddlewares.push(() => {
return function* (next) {
this.set('x-custom-middleware', 'true');
yield next;
};
});
config.customWebMiddlewares.push(() => {
return function* (next) {
this.set('x-custom-web-middleware', 'true');
yield next;
};
});
}
if (process.env.NODE_ENV !== 'test') {
var customConfig;
if (process.env.NODE_ENV === 'development') {
customConfig = path.join(root, 'config', 'config.js');
} else {
// 1. try to load `$dataDir/config.json` first, not exists then goto 2.
// 2. load config/config.js, everything in config.js will cover the same key in index.js
customConfig = path.join(dataDir, 'config.json');
if (!fs.existsSync(customConfig)) {
customConfig = path.join(root, 'config', 'config.js');
}
}
if (fs.existsSync(customConfig)) {
copy(require(customConfig)).override(config);
}
}
mkdirp.sync(config.logdir);
mkdirp.sync(config.uploadDir);
module.exports = config;
config.loadConfig = function (customConfig) {
if (!customConfig) {
return;
}
copy(customConfig).override(config);
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351