@verdaccio/config
Version:
Verdaccio Configuration
134 lines (133 loc) • 3.3 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _lodash = require("lodash");
var _ = require(".");
/**
* Helper configuration builder constructor, used to build the configuration for testing or
* programatically creating a configuration.
*/
class ConfigBuilder {
constructor(config) {
this.config = (0, _lodash.merge)({
uplinks: {},
packages: {},
security: {}
}, config);
}
static build(config) {
return new ConfigBuilder(config);
}
addPackageAccess(pattern, pkgAccess) {
// PackageAccessYaml uses string for publish/access while PackageAccess uses string[]
// The config parser normalizes these later, so the cast is safe here
this.config.packages[pattern] = pkgAccess;
return this;
}
addUplink(id, uplink) {
this.config.uplinks[id] = uplink;
return this;
}
addSecurity(security) {
this.config.security = (0, _lodash.merge)(this.config.security, security);
return this;
}
addAuth(auth) {
this.config.auth = (0, _lodash.merge)(this.config.auth, auth);
return this;
}
addLogger(log) {
this.config.log = log;
return this;
}
addStorage(storage) {
if (typeof storage === 'string') {
this.config.storage = storage;
} else {
this.config.store = storage;
}
return this;
}
addWeb(web) {
this.config.web = (0, _lodash.merge)(this.config.web, web);
return this;
}
addListen(listen) {
this.config.listen = listen;
return this;
}
addHttps(https) {
this.config.https = https;
return this;
}
addPublish(publish) {
this.config.publish = (0, _lodash.merge)(this.config.publish, publish);
return this;
}
addFlags(flags) {
this.config.flags = (0, _lodash.merge)(this.config.flags, flags);
return this;
}
addNotify(notify) {
this.config.notify = notify;
return this;
}
addMiddlewares(middlewares) {
this.config.middlewares = (0, _lodash.merge)(this.config.middlewares, middlewares);
return this;
}
addFilters(filters) {
this.config.filters = (0, _lodash.merge)(this.config.filters, filters);
return this;
}
addMaxBodySize(maxBodySize) {
this.config.max_body_size = maxBodySize;
return this;
}
addUserRateLimit(rateLimit) {
this.config.userRateLimit = (0, _lodash.merge)(this.config.userRateLimit, rateLimit);
return this;
}
addUrlPrefix(urlPrefix) {
this.config.url_prefix = urlPrefix;
return this;
}
addI18n(i18n) {
this.config.i18n = i18n;
return this;
}
addUserAgent(userAgent) {
this.config.user_agent = userAgent;
return this;
}
addHttpProxy(httpProxy) {
this.config.http_proxy = httpProxy;
return this;
}
addHttpsProxy(httpsProxy) {
this.config.https_proxy = httpsProxy;
return this;
}
addNoProxy(noProxy) {
this.config.no_proxy = noProxy;
return this;
}
addPlugins(plugins) {
this.config.plugins = plugins;
return this;
}
addNotifications(notifications) {
this.config.notifications = notifications;
return this;
}
getConfig() {
return this.config;
}
getAsYaml() {
return (0, _.fromJStoYAML)(this.config);
}
}
exports.default = ConfigBuilder;
//# sourceMappingURL=builder.js.map