feat(cli): improve banner lines dx (#7537)

* feat: improve banner ocdx

* chore: make NODE_ENV more clear

* chore: update tests and improvements

* shame on me

* chore: mode ~> rendering
This commit is contained in:
pooya parsa 2020-06-17 16:37:19 +02:00 committed by GitHub
parent 5cfaf0aca1
commit a88953fe8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 13 deletions

View File

@ -21,21 +21,34 @@ export function showBanner (nuxt, showMemoryUsage = true) {
// Name and version
const { bannerColor, badgeMessages } = nuxt.options.cli
titleLines.push(`${chalk[bannerColor].bold('Nuxt.js')} ${nuxt.constructor.version}`)
titleLines.push(`${chalk[bannerColor].bold('Nuxt.js')} @ ${nuxt.constructor.version || 'exotic'}\n`)
// Running mode
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 = `△ Server: ${envMode}\n△ Rendering: ${rendering}\n△ Target: ${chalk.bold.cyan(nuxt.options.target)}`
titleLines.push(sentence)
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}`)
if (showMemoryUsage) {
titleLines.push(getFormattedMemoryUsage())
titleLines.push('\n' + getFormattedMemoryUsage())
}
// Listeners
for (const listener of nuxt.server.listeners) {
messageLines.push(chalk.bold('Listening on: ') + chalk.underline.blue(listener.url))
messageLines.push(chalk.bold('Listening: ') + chalk.underline.blue(listener.url))
}
// Add custom badge messages

View File

@ -166,8 +166,8 @@ describe('cli/utils', () => {
expect(successBox).toHaveBeenCalledTimes(1)
expect(stdout).toHaveBeenCalledTimes(1)
expect(stdout).toHaveBeenCalledWith(expect.stringMatching('Nuxt.js'))
expect(stdout).toHaveBeenCalledWith(expect.stringMatching(`Listening on: ${listeners[0].url}`))
expect(stdout).toHaveBeenCalledWith(expect.stringMatching(`Listening on: ${listeners[1].url}`))
expect(stdout).toHaveBeenCalledWith(expect.stringMatching(`Listening: ${listeners[0].url}`))
expect(stdout).toHaveBeenCalledWith(expect.stringMatching(`Listening: ${listeners[1].url}`))
expect(stdout).toHaveBeenCalledWith(expect.stringMatching('Memory usage'))
expect(stdout).toHaveBeenCalledWith(expect.stringMatching('badgeMessage'))
stdout.mockRestore()
@ -225,9 +225,9 @@ describe('cli/utils', () => {
expect(successBox).toHaveBeenCalledTimes(1)
expect(stdout).toHaveBeenCalledTimes(1)
expect(stdout).toHaveBeenCalledWith(expect.stringMatching('Nuxt.js'))
expect(stdout).toHaveBeenCalledWith(expect.stringMatching('△ Server: production'))
expect(stdout).toHaveBeenCalledWith(expect.stringMatching('△ Rendering: client-side'))
expect(stdout).toHaveBeenCalledWith(expect.stringMatching('△ Target: static'))
expect(stdout).toHaveBeenCalledWith(expect.stringMatching('▸ Environment:'))
expect(stdout).toHaveBeenCalledWith(expect.stringMatching('▸ Rendering:'))
expect(stdout).toHaveBeenCalledWith(expect.stringMatching('▸ Target:'))
stdout.mockRestore()
})