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
|
2019-09-30 08:46:58 +00:00
|
|
|
titleLines.push(`${chalk[bannerColor].bold('Nuxt.js')} ${nuxt.constructor.version}`)
|
2019-04-11 10:04:21 +00:00
|
|
|
|
|
|
|
// Running mode
|
2020-05-07 19:08:01 +00:00
|
|
|
const rendering = nuxt.options.render.ssr ? chalk.bold.yellow('server-side') : chalk.bold.yellow('client-side')
|
|
|
|
const envMode = nuxt.options.dev ? chalk.bold.blue('development') : chalk.bold.green('production')
|
|
|
|
const sentence = `Running in ${envMode}, with ${rendering} rendering and ${chalk.bold.cyan(nuxt.options.target)} target.`
|
|
|
|
titleLines.push(sentence)
|
2019-04-11 10:04:21 +00:00
|
|
|
|
2019-04-12 17:19:46 +00:00
|
|
|
if (showMemoryUsage) {
|
|
|
|
titleLines.push(getFormattedMemoryUsage())
|
|
|
|
}
|
2019-04-11 10:04:21 +00:00
|
|
|
|
|
|
|
// Listeners
|
|
|
|
for (const listener of nuxt.server.listeners) {
|
|
|
|
messageLines.push(chalk.bold('Listening on: ') + chalk.underline.blue(listener.url))
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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')))
|
|
|
|
}
|