-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: clipanion as cli * chore: add version command * chore: update ts
- Loading branch information
1 parent
ba8cba0
commit be2f612
Showing
22 changed files
with
251 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Cli } from 'clipanion'; | ||
import { InfoCommand } from './commands/info'; | ||
import { InitCommand } from './commands/init'; | ||
import { isVersionValid, MIN_NODE_VERSION } from './utils'; | ||
import { VersionCommand } from './commands/version'; | ||
|
||
require('pkginfo')(module); | ||
const pkgVersion = module.exports.version; | ||
|
||
if (process.getuid && process.getuid() === 0) { | ||
process.emitWarning(`Verdaccio doesn't need superuser privileges. don't run it under root`); | ||
} | ||
|
||
if (!isVersionValid(process.version)) { | ||
throw new Error( | ||
`Verdaccio requires at least Node.js v${MIN_NODE_VERSION} or higher and you have installed ${process.version}, | ||
please upgrade your Node.js distribution` | ||
); | ||
} | ||
|
||
const [node, app, ...args] = process.argv; | ||
|
||
const cli = new Cli({ | ||
binaryLabel: `verdaccio`, | ||
binaryName: `${node} ${app}`, | ||
binaryVersion: pkgVersion, | ||
}); | ||
|
||
cli.register(InfoCommand); | ||
cli.register(InitCommand); | ||
cli.register(VersionCommand); | ||
cli.runExit(args, Cli.defaultContext); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import envinfo from 'envinfo'; | ||
import { Command } from 'clipanion'; | ||
|
||
export class InfoCommand extends Command { | ||
static paths = [[`--info`], [`-i`]]; | ||
|
||
async execute() { | ||
this.context.stdout.write('\nEnvironment Info:'); | ||
const data = await envinfo.run({ | ||
System: ['OS', 'CPU'], | ||
Binaries: ['node', 'yarn', 'npm', 'pnpm'], | ||
Virtualization: ['Docker'], | ||
Browsers: ['Chrome', 'Edge', 'Firefox', 'Safari'], | ||
npmGlobalPackages: ['verdaccio'], | ||
}); | ||
|
||
this.context.stdout.write(data); | ||
process.exit(0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import path from 'path'; | ||
import { Command, Option } from 'clipanion'; | ||
|
||
import { startVerdaccio, listenDefaultCallback } from '../../bootstrap'; | ||
import findConfigFile from '../../config-path'; | ||
import { parseConfigFile } from '../../utils'; | ||
|
||
require('pkginfo')(module); | ||
const pkgVersion = module.exports.version; | ||
const pkgName = module.exports.name; | ||
|
||
export const DEFAULT_PROCESS_NAME: string = 'verdaccio'; | ||
const logger = require('../../logger'); | ||
|
||
export class InitCommand extends Command { | ||
static paths = [Command.Default]; | ||
|
||
listen = Option.String('-l,--listen', { | ||
description: 'host:port number to listen on (default: localhost:4873)', | ||
}); | ||
|
||
// eslint-disable-next-line | ||
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() { | ||
try { | ||
const configPathLocation = findConfigFile(this.config as string); | ||
const verdaccioConfiguration = parseConfigFile(configPathLocation); | ||
if (!verdaccioConfiguration.self_path) { | ||
verdaccioConfiguration.self_path = path.resolve(configPathLocation); | ||
} | ||
if (!verdaccioConfiguration.https) { | ||
verdaccioConfiguration.https = { enable: false }; | ||
} | ||
|
||
logger.logger.warn({ file: configPathLocation }, 'config file - @{file}'); | ||
process.title = (verdaccioConfiguration.web && verdaccioConfiguration.web.title) || 'verdaccio'; | ||
|
||
startVerdaccio( | ||
verdaccioConfiguration, | ||
this.listen as string, | ||
configPathLocation, | ||
pkgVersion, | ||
pkgName, | ||
listenDefaultCallback | ||
); | ||
} catch (err) { | ||
process.exit(1); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Command } from 'clipanion'; | ||
require('pkginfo')(module); | ||
const pkgVersion = module.exports.version; | ||
|
||
export class VersionCommand extends Command { | ||
static paths = [[`--version`], [`-v`]]; | ||
|
||
async execute() { | ||
this.context.stdout.write(`v${pkgVersion}`); | ||
process.exit(0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.