verdaccio
Version:
A lightweight private npm proxy registry
117 lines (88 loc) • 3.54 kB
JavaScript
/* eslint no-sync:0 */
/* eslint no-empty:0 */
/**
* @prettier
*/
;
var _path = _interopRequireDefault(require("path"));
var _semver = _interopRequireDefault(require("semver"));
var _kleur = require("kleur");
var _bootstrap = require("./bootstrap");
var _configPath = _interopRequireDefault(require("./config-path"));
var _utils = require("./utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
require('pkginfo')(module);
if (process.getuid && process.getuid() === 0) {
global.console.warn((0, _kleur.bgYellow)().red('*** WARNING: Verdaccio doesn\'t need superuser privileges. Don\'t run it under root! ***'));
}
const MIN_NODE_VERSION = '6.9.0';
if (_semver.default.satisfies(process.version, `>=${MIN_NODE_VERSION}`) === false) {
global.console.error((0, _kleur.bgRed)(`Verdaccio requires at least Node.js ${MIN_NODE_VERSION} or higher, please upgrade your Node.js distribution`));
process.exit(1);
}
process.title = 'verdaccio';
const logger = require('./logger');
logger.setup(); // default setup
const envinfo = require('envinfo');
const commander = require('commander');
const pkgVersion = module.exports.version;
const pkgName = module.exports.name;
commander.option('-i, --info', 'prints debugging information about the local environment').option('-l, --listen <[host:]port>', 'host:port number to listen on (default: localhost:4873)').option('-c, --config <config.yaml>', 'use this configuration file (default: ./config.yaml)').version(pkgVersion).parse(process.argv);
function init() {
let verdaccioConfiguration;
let configPathLocation;
const cliListener = commander.listen;
try {
configPathLocation = (0, _configPath.default)(commander.config);
verdaccioConfiguration = (0, _utils.parseConfigFile)(configPathLocation);
process.title = verdaccioConfiguration.web && verdaccioConfiguration.web.title || 'verdaccio';
if (!verdaccioConfiguration.self_path) {
verdaccioConfiguration.self_path = _path.default.resolve(configPathLocation);
}
if (!verdaccioConfiguration.https) {
verdaccioConfiguration.https = {
enable: false
};
}
logger.logger.warn({
file: configPathLocation
}, 'config file - @{file}');
(0, _bootstrap.startVerdaccio)(verdaccioConfiguration, cliListener, configPathLocation, pkgVersion, pkgName, _bootstrap.listenDefaultCallback);
} catch (err) {
logger.logger.fatal({
file: configPathLocation,
err: err
}, 'cannot open config file @{file}: @{!err.message}');
process.exit(1);
}
}
if (commander.info) {
// eslint-disable-next-line no-console
console.log('\nEnvironment Info:');
(async () => {
const data = await envinfo.run({
System: ['OS', 'CPU'],
Binaries: ['Node', 'Yarn', 'npm'],
Virtualization: ['Docker'],
Browsers: ['Chrome', 'Edge', 'Firefox', 'Safari'],
npmGlobalPackages: ['verdaccio']
}); // eslint-disable-next-line no-console
console.log(data);
process.exit(1);
})();
} else if (commander.args.length == 1 && !commander.config) {
// handling "verdaccio [config]" case if "-c" is missing in command line
commander.config = commander.args.pop();
init();
} else if (commander.args.length !== 0) {
commander.help();
} else {
init();
}
process.on('uncaughtException', function (err) {
logger.logger.fatal({
err: err
}, 'uncaught exception, please report this\n@{err.stack}');
process.exit(255);
});