Skip to content
This repository was archived by the owner on Jul 27, 2021. It is now read-only.

Add Last compile and Took to the output #51

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion src/friendly-errors-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();

Expand All @@ -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', () => {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down