-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
124 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const chalk = require('chalk') | ||
|
||
const logger = {} | ||
|
||
const logTypes = { | ||
success: { | ||
color: 'green', | ||
label: 'DONE' | ||
}, | ||
error: { | ||
color: 'red', | ||
label: 'FAIL' | ||
}, | ||
warn: { | ||
color: 'yellow', | ||
label: 'WARN' | ||
}, | ||
tip: { | ||
color: 'cyan', | ||
label: 'TIP' | ||
}, | ||
wait: { | ||
color: 'blue', | ||
label: 'WAIT' | ||
} | ||
} | ||
|
||
const getLoggerFn = (color, label) => (msg, log = true) => { | ||
let newLine = false | ||
if (msg.startsWith('\n')) { | ||
if (log) msg = msg.slice(1) | ||
newLine = true | ||
} | ||
msg = chalk.reset.inverse.bold[color](` ${label} `) + ' ' + msg | ||
if (log) { | ||
console.log(newLine ? '\n' + msg : msg) | ||
} else { | ||
return msg | ||
} | ||
} | ||
|
||
for (const type in logTypes) { | ||
const { color, label } = logTypes[type] | ||
logger[type] = getLoggerFn(color, label) | ||
} | ||
|
||
module.exports = logger | ||
module.exports.getLoggerFn = getLoggerFn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const chalk = require('chalk') | ||
const logger = require('../util/logger') | ||
|
||
module.exports = class DevLogPlugin { | ||
constructor (options) { | ||
this.options = options | ||
} | ||
|
||
apply (compiler) { | ||
let isFirst = true | ||
compiler.hooks.done.tap('vuepress-log', stats => { | ||
clearScreen() | ||
|
||
const { displayHost, port, publicPath } = this.options | ||
const time = new Date().toTimeString().match(/^[\d:]+/)[0] | ||
|
||
logger.success(`\n${chalk.gray(`[${time}]`)} Build ${chalk.italic(stats.hash.slice(0, 6))} finished in ${stats.endTime - stats.startTime} ms!`) | ||
if (isFirst) { | ||
isFirst = false | ||
console.log(`\n${chalk.gray('>')} VuePress dev server listening at ${chalk.cyan(`http://${displayHost}:${port}${publicPath}`)}`) | ||
} | ||
}) | ||
compiler.hooks.invalid.tap('vuepress-log', clearScreen) | ||
} | ||
} | ||
|
||
function clearScreen () { | ||
process.stdout.write('\x1Bc') | ||
} |