cli-help.js 2.3 KB

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