cli-banner.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 env = require('std-env');
  10. const chalk = require('chalk');
  11. const index = require('./cli-index.js');
  12. const prettyBytes = require('pretty-bytes');
  13. function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
  14. const consola__default = /*#__PURE__*/_interopDefaultLegacy(consola);
  15. const env__default = /*#__PURE__*/_interopDefaultLegacy(env);
  16. const chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk);
  17. const prettyBytes__default = /*#__PURE__*/_interopDefaultLegacy(prettyBytes);
  18. function getMemoryUsage () {
  19. // https://nodejs.org/api/process.html#process_process_memoryusage
  20. const { heapUsed, rss } = process.memoryUsage();
  21. return { heap: heapUsed, rss }
  22. }
  23. function getFormattedMemoryUsage () {
  24. const { heap, rss } = getMemoryUsage();
  25. return `Memory usage: ${chalk__default['default'].bold(prettyBytes__default['default'](heap))} (RSS: ${prettyBytes__default['default'](rss)})`
  26. }
  27. function showMemoryUsage () {
  28. consola__default['default'].info(getFormattedMemoryUsage());
  29. }
  30. function showBanner (nuxt, showMemoryUsage = true) {
  31. if (env__default['default'].test) {
  32. return
  33. }
  34. if (env__default['default'].minimalCLI) {
  35. for (const listener of nuxt.server.listeners) {
  36. consola__default['default'].info('Listening on: ' + listener.url);
  37. }
  38. return
  39. }
  40. const titleLines = [];
  41. const messageLines = [];
  42. // Name and version
  43. const { bannerColor, badgeMessages } = nuxt.options.cli;
  44. titleLines.push(`${chalk__default['default'][bannerColor].bold('Nuxt')} @ ${nuxt.constructor.version || 'exotic'}\n`);
  45. const label = name => chalk__default['default'].bold.cyan(`▸ ${name}:`);
  46. // Environment
  47. const isDev = nuxt.options.dev;
  48. let _env = isDev ? 'development' : 'production';
  49. if (process.env.NODE_ENV !== _env) {
  50. _env += ` (${chalk__default['default'].cyan(process.env.NODE_ENV)})`;
  51. }
  52. titleLines.push(`${label('Environment')} ${_env}`);
  53. // Rendering
  54. const isSSR = nuxt.options.render.ssr;
  55. const rendering = isSSR ? 'server-side' : 'client-side';
  56. titleLines.push(`${label('Rendering')} ${rendering}`);
  57. // Target
  58. const target = nuxt.options.target || 'server';
  59. titleLines.push(`${label('Target')} ${target}`);
  60. if (showMemoryUsage) {
  61. titleLines.push('\n' + getFormattedMemoryUsage());
  62. }
  63. // Listeners
  64. for (const listener of nuxt.server.listeners) {
  65. messageLines.push(chalk__default['default'].bold('Listening: ') + chalk__default['default'].underline.blue(listener.url));
  66. }
  67. // Add custom badge messages
  68. if (badgeMessages.length) {
  69. messageLines.push('', ...badgeMessages);
  70. }
  71. process.stdout.write(index.successBox(messageLines.join('\n'), titleLines.join('\n')));
  72. }
  73. exports.showBanner = showBanner;
  74. exports.showMemoryUsage = showMemoryUsage;