verdaccio
Version:
A lightweight private npm proxy registry
70 lines (64 loc) • 3.03 kB
JavaScript
import { logger } from "../../logger/index.mjs";
import { initLogger, parseConfigFile } from "../../utils.mjs";
import { listenDefaultCallback } from "../../bootstrap.mjs";
import { runServer } from "../../run-server.mjs";
import { isVersionRecommended } from "../utils.mjs";
import { findConfigFile, getListenAddress } from "@verdaccio/config";
import Path from "path";
import { Command, Option } from "clipanion";
//#region src/lib/cli/commands/init.ts
var pkgVersion = "6.9.0";
var pkgName = "verdaccio";
var DEFAULT_PROCESS_NAME = "verdaccio";
var InitCommand = class extends Command {
static paths = [Command.Default];
listen = Option.String("-l,--listen", { description: "host:port number to listen on (default: localhost:4873)" });
static usage = Command.Usage({
description: `launch the server`,
details: `
This start the registry in the default port.
When used without arguments, it:
- bootstrap the server at the port \`4873\`
The optional arguments are:
- \`--listen\` to switch the default server port,
- \`--config\` to define a different configuration path location,
`,
examples: [
[`Runs the server with the default configuration`, `verdaccio`],
[`Runs the server in the port 5000`, `verdaccio --listen 5000`],
[`Runs the server by using a different absolute location of the configuration file`, `verdaccio --config /home/user/verdaccio/config.yaml`]
]
});
config = Option.String("-c,--config", { description: "use this configuration file (default: ./config.yaml)" });
async execute() {
let configPathLocation;
try {
configPathLocation = findConfigFile(this.config);
const configParsed = parseConfigFile(configPathLocation);
if (!configParsed.self_path) {
configParsed.self_path = Path.resolve(configPathLocation);
configParsed.configPath = configParsed.self_path;
}
if (!configParsed.https) configParsed.https = { enable: false };
process.title = configParsed.web && configParsed.web.title || "verdaccio";
initLogger(configParsed);
if (!isVersionRecommended(process.version)) logger.warn({
current: process.version,
recommended: "24"
}, "you are using Node.js @{current}, Verdaccio recommends Node.js v@{recommended} or higher, please consider upgrading your Node.js distribution");
logger.info({ file: configPathLocation }, "config file - @{file}");
listenDefaultCallback(await runServer(configParsed, { listenArg: this.listen }), getListenAddress(this.listen ?? configParsed.listen, logger), pkgName, pkgVersion);
} catch (err) {
console.error(`cannot open config file ${configPathLocation}: ${err.stack}`);
if (typeof logger?.logger?.fatal === "function") logger.fatal({
file: configPathLocation,
err
}, "cannot open config file @{file}: @{!err.message}");
else console.error(`cannot open config file ${configPathLocation}: ${!err.message}`);
process.exit(1);
}
}
};
//#endregion
export { DEFAULT_PROCESS_NAME, InitCommand };
//# sourceMappingURL=init.mjs.map