UNPKG

2.15 kBJavaScriptView Raw
1/*!
2 * @nuxt/cli v2.12.0 (c) 2016-2020
3
4 * - All the amazing contributors
5 * Released under the MIT License.
6 * Website: https://nuxtjs.org
7*/
8'use strict';
9
10function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
11
12const index = require('./cli-index.js');
13require('path');
14require('@nuxt/config');
15require('exit');
16require('@nuxt/utils');
17const chalk = _interopDefault(require('chalk'));
18require('std-env');
19require('wrap-ansi');
20require('boxen');
21const consola = _interopDefault(require('consola'));
22require('minimist');
23require('hable');
24require('fs');
25require('execa');
26
27async function listCommands () {
28 const commandsOrder = ['dev', 'build', 'generate', 'start', 'help'];
29
30 // Load all commands
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
58const 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
82exports.default = help;