2019-04-11 10:04:21 +00:00
|
|
|
import consola from 'consola'
|
|
|
|
import env from 'std-env'
|
|
|
|
import chalk from 'chalk'
|
|
|
|
import { successBox } from './formatting'
|
2019-04-12 17:19:46 +00:00
|
|
|
import { getFormattedMemoryUsage } from './memory'
|
2019-04-11 10:04:21 +00:00
|
|
|
|
2019-07-10 10:45:49 +00:00
|
|
|
export function showBanner (nuxt, showMemoryUsage = true) {
|
2019-04-11 10:04:21 +00:00
|
|
|
if (env.test) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (env.minimalCLI) {
|
|
|
|
for (const listener of nuxt.server.listeners) {
|
|
|
|
consola.info('Listening on: ' + listener.url)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const titleLines = []
|
|
|
|
const messageLines = []
|
|
|
|
|
|
|
|
// Name and version
|
2020-05-07 19:08:01 +00:00
|
|
|
const { bannerColor, badgeMessages } = nuxt.options.cli
|
2020-11-30 22:44:04 +00:00
|
|
|
titleLines.push(`${chalk[bannerColor].bold('Nuxt')} @ ${nuxt.constructor.version || 'exotic'}\n`)
|
2019-04-11 10:04:21 +00:00
|
|
|
|
2020-06-17 14:37:19 +00:00
|
|
|
const label = name => chalk.bold.cyan(`▸ ${name}:`)
|
|
|
|
|
|
|
|
// Environment
|
|
|
|
const isDev = nuxt.options.dev
|
|
|
|
let _env = isDev ? 'development' : 'production'
|
|
|
|
if (process.env.NODE_ENV !== _env) {
|
|
|
|
_env += ` (${chalk.cyan(process.env.NODE_ENV)})`
|
|
|
|
}
|
|
|
|
titleLines.push(`${label('Environment')} ${_env}`)
|
|
|
|
|
|
|
|
// Rendering
|
|
|
|
const isSSR = nuxt.options.render.ssr
|
|
|
|
const rendering = isSSR ? 'server-side' : 'client-side'
|
|
|
|
titleLines.push(`${label('Rendering')} ${rendering}`)
|
|
|
|
|
|
|
|
// Target
|
|
|
|
const target = nuxt.options.target || 'server'
|
|
|
|
titleLines.push(`${label('Target')} ${target}`)
|
2019-04-11 10:04:21 +00:00
|
|
|
|
2019-04-12 17:19:46 +00:00
|
|
|
if (showMemoryUsage) {
|
2020-06-17 14:37:19 +00:00
|
|
|
titleLines.push('\n' + getFormattedMemoryUsage())
|
2019-04-12 17:19:46 +00:00
|
|
|
}
|
2019-04-11 10:04:21 +00:00
|
|
|
|
|
|
|
// Listeners
|
|
|
|
for (const listener of nuxt.server.listeners) {
|
2020-06-17 14:37:19 +00:00
|
|
|
messageLines.push(chalk.bold('Listening: ') + chalk.underline.blue(listener.url))
|
2019-04-11 10:04:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add custom badge messages
|
2020-05-07 19:08:01 +00:00
|
|
|
if (badgeMessages.length) {
|
|
|
|
messageLines.push('', ...badgeMessages)
|
2019-04-11 10:04:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
process.stdout.write(successBox(messageLines.join('\n'), titleLines.join('\n')))
|
|
|
|
}
|