1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | 'use strict';
|
9 |
|
10 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
11 |
|
12 | const index = require('./cli-index.js');
|
13 | require('path');
|
14 | require('@nuxt/config');
|
15 | require('exit');
|
16 | require('@nuxt/utils');
|
17 | const chalk = _interopDefault(require('chalk'));
|
18 | require('std-env');
|
19 | require('wrap-ansi');
|
20 | require('boxen');
|
21 | const consola = _interopDefault(require('consola'));
|
22 | require('minimist');
|
23 | require('hable');
|
24 | require('fs');
|
25 | require('execa');
|
26 |
|
27 | async function listCommands () {
|
28 | const commandsOrder = ['dev', 'build', 'generate', 'start', 'help'];
|
29 |
|
30 |
|
31 | const _commands = await Promise.all(
|
32 | commandsOrder.map(cmd => index.getCommand(cmd))
|
33 | );
|
34 |
|
35 | let maxLength = 0;
|
36 | const commandsHelp = [];
|
37 |
|
38 | for (const command of _commands) {
|
39 | commandsHelp.push([command.usage, command.description]);
|
40 | maxLength = Math.max(maxLength, command.usage.length);
|
41 | }
|
42 |
|
43 | const _cmds = commandsHelp.map(([cmd, description]) => {
|
44 | const i = index.indent(maxLength + index.optionSpaces - cmd.length);
|
45 | return index.foldLines(
|
46 | chalk.green(cmd) + i + description,
|
47 | index.startSpaces + maxLength + index.optionSpaces * 2,
|
48 | index.startSpaces + index.optionSpaces
|
49 | )
|
50 | }).join('\n');
|
51 |
|
52 | const usage = index.foldLines('Usage: nuxt <command> [--help|-h]', index.startSpaces);
|
53 | const cmds = index.foldLines('Commands:', index.startSpaces) + '\n\n' + _cmds;
|
54 |
|
55 | process.stderr.write(index.colorize(`${usage}\n\n${cmds}\n\n`));
|
56 | }
|
57 |
|
58 | const help = {
|
59 | name: 'help',
|
60 | description: 'Shows help for <command>',
|
61 | usage: 'help <command>',
|
62 | options: {
|
63 | help: index.common.help,
|
64 | version: index.common.version
|
65 | },
|
66 | async run (cmd) {
|
67 | const [name] = cmd._argv;
|
68 | if (!name) {
|
69 | return listCommands()
|
70 | }
|
71 | const command = await index.getCommand(name);
|
72 |
|
73 | if (!command) {
|
74 | consola.info(`Unknown command: ${name}`);
|
75 | return
|
76 | }
|
77 |
|
78 | index.NuxtCommand.from(command).showHelp();
|
79 | }
|
80 | };
|
81 |
|
82 | exports.default = help;
|