1 | const chalk = require('chalk');
|
2 | const open = require('opn');
|
3 |
|
4 | const pkg = require('../../package.json');
|
5 |
|
6 | const Command = require('./Command');
|
7 |
|
8 | class HelpCommandError extends Command.CommandError {
|
9 | constructor(...args) {
|
10 | super(...args);
|
11 | this.name = 'HelpCommandError';
|
12 | }
|
13 | }
|
14 |
|
15 | module.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 |
|
33 | run(cli, options = {}) {
|
34 | const { log } = console;
|
35 | const [, target] = cli.input;
|
36 |
|
37 |
|
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(
|
47 | `The command '${target}' has not been installed`
|
48 | );
|
49 | }
|
50 |
|
51 | if (options.stdout === false) {
|
52 | return command.help();
|
53 | }
|
54 |
|
55 |
|
56 | log(command.help());
|
57 | }
|
58 | };
|
59 |
|
60 | module.exports.HelpCommandError = HelpCommandError;
|