Skip to content

Commit

Permalink
feat($cli): --no-clear-screen flag (close: #1421)
Browse files Browse the repository at this point in the history
  • Loading branch information
ulivz committed Mar 9, 2019
1 parent d1ea2da commit e5f51de
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
3 changes: 2 additions & 1 deletion packages/@vuepress/core/lib/node/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ module.exports = class DevProcess extends EventEmitter {
.use(DevLogPlugin, [{
port: this.port,
displayHost: this.displayHost,
publicPath: this.context.base
publicPath: this.context.base,
clearScreen: this.context.options.clearScreen
}])

config = config.toConfig()
Expand Down
11 changes: 8 additions & 3 deletions packages/@vuepress/core/lib/node/webpack/DevLogPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ module.exports = class DevLogPlugin {

apply (compiler) {
let isFirst = true
const { displayHost, port, publicPath, clearScreen: shouldClearScreen = true } = this.options

compiler.hooks.done.tap('vuepress-log', stats => {
clearScreen()
if (shouldClearScreen) {
clearScreen()
}

const { displayHost, port, publicPath } = this.options
const time = new Date().toTimeString().match(/^[\d:]+/)[0]
const displayUrl = `http://${displayHost}:${port}${publicPath}`

Expand All @@ -40,7 +43,9 @@ module.exports = class DevLogPlugin {
logger.developer(`It took a total of ${chalk.cyan(`${duration}ms`)} to run the ${chalk.cyan('vuepress dev')} for the first time.`)
}
})
compiler.hooks.invalid.tap('vuepress-log', clearScreen)
if (shouldClearScreen) {
compiler.hooks.invalid.tap('vuepress-log', clearScreen)
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion packages/docs/docs/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ See [port](../config/README.md#port).
See [temp](../config/README.md#temp).

### -c, --cache [cache]
### -no--cache [cache]
### -no--cache
See [cache](../config/README.md#cache).

### --debug
Expand All @@ -36,6 +36,9 @@ See [host](../config/README.md#host).
### --open
Open browser when ready.

### --no-clear-screen
do not clear screen when dev server is ready.

## eject

Copy the default theme into `.vuepress/theme` for customization.
Expand Down
3 changes: 3 additions & 0 deletions packages/docs/docs/zh/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ vuepress <command> targetDir [options]
### --open
当服务端准备就绪时自动打开浏览器。

### --no-clear-screen
当 dev server 就绪时不清除屏幕。

## eject

将默认主题复制到 `.vuepress/theme` 目录,以供自定义。
Expand Down
1 change: 1 addition & 0 deletions packages/vuepress/lib/registerCoreCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = function (cli, options) {
.option('-c, --cache [cache]', 'set the directory of cache')
.option('--host <host>', 'use specified host (default: 0.0.0.0)')
.option('--no-cache', 'clean the cache before build')
.option('--no-clear-screen', 'do not clear screen when dev server is ready')
.option('--debug', 'start development server in debug mode')
.option('--silent', 'start development server in silent mode')
.option('--open', 'open browser when ready')
Expand Down

0 comments on commit e5f51de

Please sign in to comment.