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
2019-09-30 08:46:58 +00:00
const { bannerColor } = nuxt . options . cli
titleLines . push ( ` ${ chalk [ bannerColor ] . bold ( 'Nuxt.js' ) } ${ nuxt . constructor . version } ` )
2019-04-11 10:04:21 +00:00
// Running mode
titleLines . push ( ` Running in ${ nuxt . options . dev ? chalk . bold . blue ( 'development' ) : chalk . bold . green ( 'production' ) } mode ( ${ chalk . bold ( nuxt . options . mode ) } ) ` )
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
if ( nuxt . options . cli . badgeMessages . length ) {
messageLines . push ( '' , ... nuxt . options . cli . badgeMessages )
}
process . stdout . write ( successBox ( messageLines . join ( '\n' ) , titleLines . join ( '\n' ) ) )
}