diff --git a/src/friendly-errors-plugin.js b/src/friendly-errors-plugin.js index 3ae8041..7e01693 100644 --- a/src/friendly-errors-plugin.js +++ b/src/friendly-errors-plugin.js @@ -23,6 +23,21 @@ const defaultFormatters = [ require('./formatters/defaultError'), ]; +const defaultOutputOptions = { + dateString: { + color: 'blue', + }, + took: { + // can be "ms" or "s" + on: 'ms', + // greater than 5000 ms, it will be displayed on red + // (!) if took.on === 's' then took.red must be on seconds too + red: 5000, + }, + displayLastCompile: true, + displayTook: true, +}; + class FriendlyErrorsWebpackPlugin { constructor(options) { @@ -32,10 +47,10 @@ class FriendlyErrorsWebpackPlugin { this.shouldClearConsole = options.clearConsole == null ? true : Boolean(options.clearConsole); this.formatters = concat(defaultFormatters, options.additionalFormatters); this.transformers = concat(defaultTransformers, options.additionalTransformers); + this.output = Object.assign({}, defaultOutputOptions, options.output); } apply(compiler) { - compiler.plugin('done', stats => { this.clearConsole(); @@ -55,6 +70,19 @@ class FriendlyErrorsWebpackPlugin { if (hasWarnings) { this.displayErrors(extractErrorsFromStats(stats, 'warnings'), 'warning'); } + + output.log(); + + if(this.output.displayLastCompile) { + this.displayLastCompile(this.output.dateString.color); + } + + if(this.output.displayTook){ + this.displayTook(stats, this.output.took); + } + + output.log(); + }); compiler.plugin('invalid', () => { @@ -100,6 +128,25 @@ class FriendlyErrorsWebpackPlugin { formatErrors(topErrors, this.formatters, severity) .forEach(chunk => output.log(chunk)); } + + displayLastCompile(dateStringColor) { + const date = new Date(); + const lastCompile = chalk[dateStringColor](date.toLocaleDateString()) + " at " + chalk[dateStringColor](date.toLocaleTimeString()); + + output.log("Last compile: " + lastCompile); + } + + displayTook(stats, tookOptions) { + let time = getCompileTime(stats); + + if (tookOptions.on === 's') { + time = time / 1000; + } + + const took = (time < tookOptions.red) ? chalk.green(time + tookOptions.on) : chalk.red(time + tookOptions.on); + + output.log("Took: " + took); + } } function extractErrorsFromStats(stats, type) { diff --git a/src/output.js b/src/output.js index b107c14..002db8b 100644 --- a/src/output.js +++ b/src/output.js @@ -51,7 +51,7 @@ class Debugger { title (severity, title, subtitle) { if (this.enabled) { const date = new Date(); - const dateString = chalk.grey(date.toLocaleTimeString()); + const dateString = chalk.blue(date.toLocaleTimeString()); const titleFormatted = colors.formatTitle(severity, title); const subTitleFormatted = colors.formatText(severity, subtitle); const message = `${titleFormatted} ${subTitleFormatted}`