2018-11-08 09:15:56 +00:00
|
|
|
import chalk from 'chalk'
|
|
|
|
import { indent, foldLines, startSpaces, optionSpaces, colorize } from './utils/formatting'
|
2018-12-20 11:15:48 +00:00
|
|
|
import getCommand from './commands'
|
2018-11-08 09:15:56 +00:00
|
|
|
|
|
|
|
export default async function listCommands() {
|
|
|
|
const commandsOrder = ['dev', 'build', 'generate', 'start', 'help']
|
|
|
|
|
|
|
|
// Load all commands
|
|
|
|
const _commands = await Promise.all(
|
2018-12-20 11:15:48 +00:00
|
|
|
commandsOrder.map(cmd => getCommand(cmd))
|
2018-11-08 09:15:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
let maxLength = 0
|
|
|
|
const commandsHelp = []
|
|
|
|
|
2019-01-14 11:56:30 +00:00
|
|
|
for (const command of _commands) {
|
|
|
|
commandsHelp.push([command.usage, command.description])
|
|
|
|
maxLength = Math.max(maxLength, command.usage.length)
|
2018-11-08 09:15:56 +00:00
|
|
|
}
|
|
|
|
|
2018-12-12 06:31:49 +00:00
|
|
|
const _cmds = commandsHelp.map(([cmd, description]) => {
|
2018-11-08 09:15:56 +00:00
|
|
|
const i = indent(maxLength + optionSpaces - cmd.length)
|
|
|
|
return foldLines(
|
|
|
|
chalk.green(cmd) + i + description,
|
|
|
|
startSpaces + maxLength + optionSpaces * 2,
|
|
|
|
startSpaces + optionSpaces
|
|
|
|
)
|
|
|
|
}).join('\n')
|
|
|
|
|
|
|
|
const usage = foldLines(`Usage: nuxt <command> [--help|-h]`, startSpaces)
|
2018-12-12 06:31:49 +00:00
|
|
|
const cmds = foldLines(`Commands:`, startSpaces) + '\n\n' + _cmds
|
2018-11-08 09:15:56 +00:00
|
|
|
|
2018-12-12 06:31:49 +00:00
|
|
|
process.stderr.write(colorize(`${usage}\n\n${cmds}\n\n`))
|
2018-11-08 09:15:56 +00:00
|
|
|
}
|