mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-30 23:32:38 +00:00
misc: improve onReady CLI experience (#3143)
This commit is contained in:
parent
c42ef4c0af
commit
948d56622e
@ -80,4 +80,6 @@ if (nuxt.options.render.ssr === true) {
|
|||||||
|
|
||||||
const { port, host } = getLatestHost(argv)
|
const { port, host } = getLatestHost(argv)
|
||||||
|
|
||||||
nuxt.listen(port, host)
|
nuxt.listen(port, host).then(() => {
|
||||||
|
nuxt.showReady()
|
||||||
|
})
|
||||||
|
@ -46,9 +46,7 @@ export default class Builder {
|
|||||||
// Shared spinner
|
// Shared spinner
|
||||||
this.spinner = createSpinner({ minimal: this.options.minimalCLI })
|
this.spinner = createSpinner({ minimal: this.options.minimalCLI })
|
||||||
this.spinner.enabled = !this.options.test
|
this.spinner.enabled = !this.options.test
|
||||||
this.logUpdate = logUpdate.create(process.stdout, {
|
this.logUpdate = logUpdate.create(process.stdout)
|
||||||
showCursor: true
|
|
||||||
})
|
|
||||||
|
|
||||||
// Helper to resolve build paths
|
// Helper to resolve build paths
|
||||||
this.relativeToBuild = (...args) =>
|
this.relativeToBuild = (...args) =>
|
||||||
|
@ -16,6 +16,7 @@ export default class WebpackBaseConfig {
|
|||||||
this.name = options.name
|
this.name = options.name
|
||||||
this.isServer = options.isServer
|
this.isServer = options.isServer
|
||||||
this.builder = builder
|
this.builder = builder
|
||||||
|
this.nuxt = this.builder.nuxt
|
||||||
this.isStatic = builder.isStatic
|
this.isStatic = builder.isStatic
|
||||||
this.options = builder.options
|
this.options = builder.options
|
||||||
this.spinner = builder.spinner
|
this.spinner = builder.spinner
|
||||||
@ -207,7 +208,12 @@ export default class WebpackBaseConfig {
|
|||||||
profile: this.options.build.profile,
|
profile: this.options.build.profile,
|
||||||
name: this.isServer ? 'server' : 'client',
|
name: this.isServer ? 'server' : 'client',
|
||||||
color: this.isServer ? 'orange' : 'green',
|
color: this.isServer ? 'orange' : 'green',
|
||||||
logUpdate: this.logUpdate
|
logUpdate: this.logUpdate,
|
||||||
|
done: () => {
|
||||||
|
if (this.options.dev) {
|
||||||
|
this.nuxt.showReady(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import enableDestroy from 'server-destroy'
|
|||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
import chalk from 'chalk'
|
import chalk from 'chalk'
|
||||||
import fs from 'fs-extra'
|
import fs from 'fs-extra'
|
||||||
|
import clear from 'clear'
|
||||||
|
|
||||||
import Options from '../common/options'
|
import Options from '../common/options'
|
||||||
import { sequence, printError } from '../common/utils'
|
import { sequence, printError } from '../common/utils'
|
||||||
@ -18,10 +19,14 @@ import Renderer from './renderer'
|
|||||||
const debug = Debug('nuxt:')
|
const debug = Debug('nuxt:')
|
||||||
debug.color = 5
|
debug.color = 5
|
||||||
|
|
||||||
|
const IS_WINDOWS = /^win/.test(process.platform)
|
||||||
|
const READY_ICON = IS_WINDOWS ? '' : '🚀'
|
||||||
|
|
||||||
export default class Nuxt {
|
export default class Nuxt {
|
||||||
constructor(options = {}) {
|
constructor(options = {}) {
|
||||||
this.options = Options.from(options)
|
this.options = Options.from(options)
|
||||||
|
|
||||||
|
this.readyMessage = null
|
||||||
this.initialized = false
|
this.initialized = false
|
||||||
this.onError = this.onError.bind(this)
|
this.onError = this.onError.bind(this)
|
||||||
|
|
||||||
@ -116,6 +121,27 @@ export default class Nuxt {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
showReady(doClear = false) {
|
||||||
|
if (!this.readyMessage || this.options.test) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.options.minimalCLI) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('[READY] ', this.readyMessage)
|
||||||
|
} else {
|
||||||
|
if (doClear) {
|
||||||
|
clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
process.stdout.write(
|
||||||
|
'\n' +
|
||||||
|
chalk.bgGreen.black(' READY ') +
|
||||||
|
chalk.green(` ${READY_ICON} ${this.readyMessage}\n`)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
listen(port = 3000, host = 'localhost') {
|
listen(port = 3000, host = 'localhost') {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const server = this.renderer.app.listen(
|
const server = this.renderer.app.listen(
|
||||||
@ -126,14 +152,7 @@ export default class Nuxt {
|
|||||||
return reject(err)
|
return reject(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.options.test) {
|
this.readyMessage = `Listening on ${host}:${port}`
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log(
|
|
||||||
'\n' +
|
|
||||||
chalk.bgGreen.black(' READY ') +
|
|
||||||
chalk.green(` Listening on ${host}:${port}\n`)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close server on nuxt close
|
// Close server on nuxt close
|
||||||
this.hook(
|
this.hook(
|
||||||
|
@ -78,6 +78,7 @@
|
|||||||
"caniuse-lite": "^1.0.30000821",
|
"caniuse-lite": "^1.0.30000821",
|
||||||
"chalk": "^2.3.2",
|
"chalk": "^2.3.2",
|
||||||
"chokidar": "^2.0.3",
|
"chokidar": "^2.0.3",
|
||||||
|
"clear": "^0.1.0",
|
||||||
"compression": "^1.7.1",
|
"compression": "^1.7.1",
|
||||||
"connect": "^3.6.5",
|
"connect": "^3.6.5",
|
||||||
"css-loader": "^0.28.11",
|
"css-loader": "^0.28.11",
|
||||||
|
@ -1504,6 +1504,10 @@ clean-css@4.1.x:
|
|||||||
dependencies:
|
dependencies:
|
||||||
source-map "0.5.x"
|
source-map "0.5.x"
|
||||||
|
|
||||||
|
clear@^0.1.0:
|
||||||
|
version "0.1.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/clear/-/clear-0.1.0.tgz#b81b1e03437a716984fd7ac97c87d73bdfe7048a"
|
||||||
|
|
||||||
cli-cursor@^2.0.0, cli-cursor@^2.1.0:
|
cli-cursor@^2.0.0, cli-cursor@^2.1.0:
|
||||||
version "2.1.0"
|
version "2.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-2.1.0.tgz#b35dac376479facc3e94747d41d0d0f5238ffcb5"
|
resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-2.1.0.tgz#b35dac376479facc3e94747d41d0d0f5238ffcb5"
|
||||||
|
Loading…
Reference in New Issue
Block a user