UNPKG

1.2 kBJavaScriptView Raw
1const chalk = require('chalk');
2const open = require('opn');
3
4const pkg = require('../../package.json');
5
6const Command = require('./Command');
7
8class HelpCommandError extends Command.CommandError {
9 constructor(...args) {
10 super(...args);
11 this.name = 'HelpCommandError';
12 }
13}
14
15module.exports = class HelpCommand extends Command {
16 help() {
17 return chalk`
18 {blue help} v${pkg.version}
19
20 Displays help for a given installed webpack command.
21
22 {underline Usage}
23 $ webpack help <command>
24
25 {underline Examples}
26 $ webpack help
27 $ webpack help init
28 $ webpack help serve
29`;
30 }
31
32 // eslint-disable-next-line consistent-return
33 run(cli, options = {}) {
34 const { log } = console;
35 const [, target] = cli.input;
36
37 /* istanbul ignore if */
38 if (!target) {
39 open('https://webpack.js.org/');
40 return '';
41 }
42
43 const command = cli.commands[target];
44
45 if (!command) {
46 throw new HelpCommandError(`The command '${target}' has not been installed`);
47 }
48
49 if (options.stdout === false) {
50 return command.help();
51 }
52
53 /* istanbul ignore next */
54 log(command.help());
55 }
56};
57
58module.exports.HelpCommandError = HelpCommandError;