{"version":3,"file":"init.mjs","names":[],"sources":["../../../../src/lib/cli/commands/init.ts"],"sourcesContent":["import { Command, Option } from 'clipanion';\nimport path from 'path';\n\nimport { findConfigFile, getListenAddress } from '@verdaccio/config';\n\nimport { listenDefaultCallback } from '../../bootstrap';\nimport { logger } from '../../logger';\nimport { runServer } from '../../run-server';\nimport { initLogger, parseConfigFile } from '../../utils';\nimport { RECOMMENDED_NODE_VERSION, isVersionRecommended } from '../utils';\n\nconst pkgVersion = process.env.PACKAGE_VERSION || 'dev';\nconst pkgName = 'verdaccio';\n\nexport const DEFAULT_PROCESS_NAME: string = 'verdaccio';\n\nexport class InitCommand extends Command {\n  static paths = [Command.Default];\n\n  listen = Option.String('-l,--listen', {\n    description: 'host:port number to listen on (default: localhost:4873)',\n  });\n\n  static usage = Command.Usage({\n    description: `launch the server`,\n    details: `\n      This start the registry in the default port.\n\n      When used without arguments, it:\n\n      - bootstrap the server at the port  \\`4873\\`\n\n      The optional arguments are:\n\n      - \\`--listen\\` to switch the default server port,\n      - \\`--config\\` to define a different configuration path location,\n\n    `,\n    examples: [\n      [`Runs the server with the default configuration`, `verdaccio`],\n      [`Runs the server in the port 5000`, `verdaccio --listen 5000`],\n      [\n        `Runs the server by using a different absolute location of the configuration file`,\n        `verdaccio --config /home/user/verdaccio/config.yaml`,\n      ],\n    ],\n  });\n\n  config = Option.String('-c,--config', {\n    description: 'use this configuration file (default: ./config.yaml)',\n  });\n\n  async execute() {\n    let configPathLocation;\n    try {\n      configPathLocation = findConfigFile(this.config as string);\n      const configParsed: ReturnType<any> = parseConfigFile(configPathLocation);\n      if (!configParsed.self_path) {\n        configParsed.self_path = path.resolve(configPathLocation);\n        // compatibility with 6.x plugins\n        configParsed.configPath = configParsed.self_path;\n      }\n      if (!configParsed.https) {\n        configParsed.https = { enable: false };\n      }\n\n      process.title = (configParsed.web && configParsed.web.title) || 'verdaccio';\n\n      initLogger(configParsed);\n      if (!isVersionRecommended(process.version)) {\n        logger.warn(\n          { current: process.version, recommended: RECOMMENDED_NODE_VERSION },\n          'you are using Node.js @{current}, Verdaccio recommends Node.js v@{recommended} or higher, please consider upgrading your Node.js distribution'\n        );\n      }\n      logger.info({ file: configPathLocation }, 'config file  - @{file}');\n      const webServer = await runServer(configParsed, { listenArg: this.listen as string });\n      const listen = (this.listen as string) ?? configParsed.listen;\n      const addr = getListenAddress(listen, logger);\n      listenDefaultCallback(webServer, addr, pkgName, pkgVersion);\n    } catch (err: any) {\n      console.error(`cannot open config file ${configPathLocation}: ${err.stack}`);\n      // @ts-expect-error\n      if (typeof logger?.logger?.fatal === 'function') {\n        logger.fatal(\n          { file: configPathLocation, err: err },\n          'cannot open config file @{file}: @{!err.message}'\n        );\n      } else {\n        console.error(`cannot open config file ${configPathLocation}: ${!err.message}`);\n      }\n      process.exit(1);\n    }\n  }\n}\n"],"mappings":";;;;;;;;;AAWA,IAAM,aAAA;AACN,IAAM,UAAU;AAEhB,IAAa,uBAA+B;AAE5C,IAAa,cAAb,cAAiC,QAAQ;CACvC,OAAO,QAAQ,CAAC,QAAQ,OAAO;CAE/B,SAAS,OAAO,OAAO,eAAe,EACpC,aAAa,0DACf,CAAC;CAED,OAAO,QAAQ,QAAQ,MAAM;EAC3B,aAAa;EACb,SAAS;;;;;;;;;;;;;EAaT,UAAU;GACR,CAAC,kDAAkD,WAAW;GAC9D,CAAC,oCAAoC,yBAAyB;GAC9D,CACE,oFACA,qDACF;EACF;CACF,CAAC;CAED,SAAS,OAAO,OAAO,eAAe,EACpC,aAAa,uDACf,CAAC;CAED,MAAM,UAAU;EACd,IAAI;EACJ,IAAI;GACF,qBAAqB,eAAe,KAAK,MAAgB;GACzD,MAAM,eAAgC,gBAAgB,kBAAkB;GACxE,IAAI,CAAC,aAAa,WAAW;IAC3B,aAAa,YAAY,KAAK,QAAQ,kBAAkB;IAExD,aAAa,aAAa,aAAa;GACzC;GACA,IAAI,CAAC,aAAa,OAChB,aAAa,QAAQ,EAAE,QAAQ,MAAM;GAGvC,QAAQ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