mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-01-20 22:52:46 -05:00
Fix more eslint warnings, add doc
This commit is contained in:
parent
7c6c2d2932
commit
2a1f1a7dfa
3 changed files with 64 additions and 32 deletions
32
lib/cli.js
32
lib/cli.js
|
@ -47,7 +47,8 @@ if (commander.args.length != 0) {
|
||||||
commander.help();
|
commander.help();
|
||||||
}
|
}
|
||||||
|
|
||||||
let config, config_path;
|
let config;
|
||||||
|
let config_path;
|
||||||
try {
|
try {
|
||||||
if (commander.config) {
|
if (commander.config) {
|
||||||
config_path = Path.resolve(commander.config);
|
config_path = Path.resolve(commander.config);
|
||||||
|
@ -63,10 +64,17 @@ try {
|
||||||
|
|
||||||
afterConfigLoad();
|
afterConfigLoad();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve all addresses defined in the config file.
|
||||||
|
* Verdaccio is able to listen multiple ports
|
||||||
|
* eg:
|
||||||
|
* listen:
|
||||||
|
- localhost:5555
|
||||||
|
- localhost:5557
|
||||||
|
*/
|
||||||
function get_listen_addresses() {
|
function get_listen_addresses() {
|
||||||
// command line || config file || default
|
// command line || config file || default
|
||||||
let addresses;
|
let addresses;
|
||||||
|
|
||||||
if (commander.listen) {
|
if (commander.listen) {
|
||||||
addresses = [commander.listen];
|
addresses = [commander.listen];
|
||||||
} else if (Array.isArray(config.listen)) {
|
} else if (Array.isArray(config.listen)) {
|
||||||
|
@ -76,7 +84,6 @@ function get_listen_addresses() {
|
||||||
} else {
|
} else {
|
||||||
addresses = ['4873'];
|
addresses = ['4873'];
|
||||||
}
|
}
|
||||||
|
|
||||||
addresses = addresses.map(function(addr) {
|
addresses = addresses.map(function(addr) {
|
||||||
let parsed_addr = Utils.parse_address(addr);
|
let parsed_addr = Utils.parse_address(addr);
|
||||||
|
|
||||||
|
@ -93,12 +100,17 @@ function get_listen_addresses() {
|
||||||
return addresses;
|
return addresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trigger the server after configuration has been loaded.
|
||||||
|
*/
|
||||||
function afterConfigLoad() {
|
function afterConfigLoad() {
|
||||||
if (!config.self_path) config.self_path = Path.resolve(config_path);
|
if (!config.self_path) {
|
||||||
if (!config.https) config.https = {enable: false};
|
config.self_path = Path.resolve(config_path);
|
||||||
|
}
|
||||||
let app = server(config);
|
if (!config.https) {
|
||||||
|
config.https = {enable: false};
|
||||||
|
}
|
||||||
|
const app = server(config);
|
||||||
get_listen_addresses().forEach(function(addr) {
|
get_listen_addresses().forEach(function(addr) {
|
||||||
let webServer;
|
let webServer;
|
||||||
|
|
||||||
|
@ -173,7 +185,7 @@ function afterConfigLoad() {
|
||||||
}
|
}
|
||||||
|
|
||||||
process.on('uncaughtException', function(err) {
|
process.on('uncaughtException', function(err) {
|
||||||
logger.logger.fatal( {err: err}
|
logger.logger.fatal( {err: err},
|
||||||
, 'uncaught exception, please report this\n@{err.stack}' );
|
'uncaught exception, please report this\n@{err.stack}' );
|
||||||
process.exit(255);
|
process.exit(255);
|
||||||
});
|
});
|
||||||
|
|
|
@ -8,8 +8,9 @@ const Utils = require('./utils');
|
||||||
const pkgJSON = require('../package.json');
|
const pkgJSON = require('../package.json');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Match the level based on buyan severity scale
|
||||||
* @param {*} x
|
* @param {*} x severity level
|
||||||
|
* @return {String} security level
|
||||||
*/
|
*/
|
||||||
function getlvl(x) {
|
function getlvl(x) {
|
||||||
switch(true) {
|
switch(true) {
|
||||||
|
@ -23,11 +24,18 @@ function getlvl(x) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.setup = function(logs) {
|
/**
|
||||||
|
* Setup the Buyan logger
|
||||||
|
* @param {*} logs list of log configuration
|
||||||
|
*/
|
||||||
|
function setup(logs) {
|
||||||
let streams = [];
|
let streams = [];
|
||||||
if (logs == null) logs = [{type: 'stdout', format: 'pretty', level: 'http'}];
|
if (logs == null) {
|
||||||
|
logs = [{type: 'stdout', format: 'pretty', level: 'http'}];
|
||||||
|
}
|
||||||
|
|
||||||
logs.forEach(function(target) {
|
logs.forEach(function(target) {
|
||||||
|
// create a stream for each log configuration
|
||||||
const stream = new Stream();
|
const stream = new Stream();
|
||||||
stream.writable = true;
|
stream.writable = true;
|
||||||
|
|
||||||
|
@ -74,7 +82,8 @@ module.exports.setup = function(logs) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
let logger = new Logger({
|
// buyan default configuration
|
||||||
|
const logger = new Logger({
|
||||||
name: pkgJSON.name,
|
name: pkgJSON.name,
|
||||||
streams: streams,
|
streams: streams,
|
||||||
serializers: {
|
serializers: {
|
||||||
|
@ -85,14 +94,14 @@ module.exports.setup = function(logs) {
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports.logger = logger;
|
module.exports.logger = logger;
|
||||||
};
|
}
|
||||||
|
|
||||||
// adopted from socket.io
|
// adopted from socket.io
|
||||||
// this part was converted to coffee-script and back again over the years,
|
// this part was converted to coffee-script and back again over the years,
|
||||||
// so it might look weird
|
// so it might look weird
|
||||||
|
|
||||||
// level to color
|
// level to color
|
||||||
let levels = {
|
const levels = {
|
||||||
fatal: chalk.red,
|
fatal: chalk.red,
|
||||||
error: chalk.red,
|
error: chalk.red,
|
||||||
warn: chalk.yellow,
|
warn: chalk.yellow,
|
||||||
|
@ -104,27 +113,35 @@ let levels = {
|
||||||
|
|
||||||
let max = 0;
|
let max = 0;
|
||||||
for (let l in levels) {
|
for (let l in levels) {
|
||||||
|
if (Object.prototype.hasOwnProperty.call(levels, l)) {
|
||||||
max = Math.max(max, l.length);
|
max = Math.max(max, l.length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Apply whitespaces based on the length
|
||||||
* @param {*} str
|
* @param {*} str the log message
|
||||||
|
* @return {String}
|
||||||
*/
|
*/
|
||||||
function pad(str) {
|
function pad(str) {
|
||||||
if (str.length < max) return str + ' '.repeat(max - str.length);
|
if (str.length < max) {
|
||||||
|
return str + ' '.repeat(max - str.length);
|
||||||
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a string
|
* Apply colors to a string based on level parameters.
|
||||||
* @param {*} type
|
* @param {*} type
|
||||||
* @param {*} msg
|
* @param {*} msg
|
||||||
* @param {*} obj
|
* @param {*} obj
|
||||||
* @param {*} colors
|
* @param {*} colors
|
||||||
|
* @return {String}
|
||||||
*/
|
*/
|
||||||
function print(type, msg, obj, colors) {
|
function print(type, msg, obj, colors) {
|
||||||
if (typeof type === 'number') type = getlvl(type);
|
if (typeof type === 'number') {
|
||||||
|
type = getlvl(type);
|
||||||
|
}
|
||||||
let finalmsg = msg.replace(/@{(!?[$A-Za-z_][$0-9A-Za-z\._]*)}/g, function(_, name) {
|
let finalmsg = msg.replace(/@{(!?[$A-Za-z_][$0-9A-Za-z\._]*)}/g, function(_, name) {
|
||||||
let str = obj;
|
let str = obj;
|
||||||
let is_error;
|
let is_error;
|
||||||
|
@ -168,11 +185,12 @@ function print(type, msg, obj, colors) {
|
||||||
default: '---',
|
default: '---',
|
||||||
}];
|
}];
|
||||||
|
|
||||||
let sub = subsystems[colors ? 0 : 1][obj.sub] || subsystems[+!colors].default;
|
const sub = subsystems[colors ? 0 : 1][obj.sub] || subsystems[+!colors].default;
|
||||||
if (colors) {
|
if (colors) {
|
||||||
// return ' \033[' + levels[type] + 'm' + (pad(type)) + '\033[39m ' + sub + ' ' + finalmsg
|
|
||||||
return ` ${levels[type]((pad(type)))}${chalk.white(`${sub} ${finalmsg}`)}`;
|
return ` ${levels[type]((pad(type)))}${chalk.white(`${sub} ${finalmsg}`)}`;
|
||||||
} else {
|
} else {
|
||||||
return ` ${(pad(type))}${sub} ${finalmsg}`;
|
return ` ${(pad(type))}${sub} ${finalmsg}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports.setup = setup;
|
||||||
|
|
|
@ -26,10 +26,12 @@ class Storage {
|
||||||
// Proxy and Local classes should have similar API interfaces
|
// Proxy and Local classes should have similar API interfaces
|
||||||
this.uplinks = {};
|
this.uplinks = {};
|
||||||
for (let p in config.uplinks) {
|
for (let p in config.uplinks) {
|
||||||
|
if (Object.prototype.hasOwnProperty.call(config.uplinks, p)) {
|
||||||
// instance for each up-link definition
|
// instance for each up-link definition
|
||||||
this.uplinks[p] = new Proxy(config.uplinks[p], config);
|
this.uplinks[p] = new Proxy(config.uplinks[p], config);
|
||||||
this.uplinks[p].upname = p;
|
this.uplinks[p].upname = p;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// an instance for local storage
|
// an instance for local storage
|
||||||
this.local = new Local(config);
|
this.local = new Local(config);
|
||||||
this.logger = Logger.logger.child();
|
this.logger = Logger.logger.child();
|
||||||
|
@ -254,14 +256,14 @@ class Storage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (uplink == null) {
|
if (uplink == null) {
|
||||||
uplink = Proxy({
|
uplink = new Proxy({
|
||||||
url: file.url,
|
url: file.url,
|
||||||
_autogenerated: true,
|
_autogenerated: true,
|
||||||
}, self.config);
|
}, self.config);
|
||||||
}
|
}
|
||||||
|
|
||||||
let savestream = self.local.add_tarball(name, filename);
|
let savestream = self.local.add_tarball(name, filename);
|
||||||
var on_open = function() {
|
let on_open = function() {
|
||||||
on_open = function() {}; // prevent it from being called twice
|
on_open = function() {}; // prevent it from being called twice
|
||||||
let rstream2 = uplink.get_url(file.url);
|
let rstream2 = uplink.get_url(file.url);
|
||||||
rstream2.on('error', function(err) {
|
rstream2.on('error', function(err) {
|
||||||
|
@ -533,14 +535,14 @@ class Storage {
|
||||||
static _merge_versions(local, up, config) {
|
static _merge_versions(local, up, config) {
|
||||||
// copy new versions to a cache
|
// copy new versions to a cache
|
||||||
// NOTE: if a certain version was updated, we can't refresh it reliably
|
// NOTE: if a certain version was updated, we can't refresh it reliably
|
||||||
for (var i in up.versions) {
|
for (let i in up.versions) {
|
||||||
if (local.versions[i] == null) {
|
if (local.versions[i] == null) {
|
||||||
local.versions[i] = up.versions[i];
|
local.versions[i] = up.versions[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// refresh dist-tags
|
// refresh dist-tags
|
||||||
for (var i in up['dist-tags']) {
|
for (let i in up['dist-tags']) {
|
||||||
if (local['dist-tags'][i] !== up['dist-tags'][i]) {
|
if (local['dist-tags'][i] !== up['dist-tags'][i]) {
|
||||||
local['dist-tags'][i] = up['dist-tags'][i];
|
local['dist-tags'][i] = up['dist-tags'][i];
|
||||||
if (i === 'latest') {
|
if (i === 'latest') {
|
||||||
|
|
Loading…
Add table
Reference in a new issue