2023-12-18 13:12:25 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
module.exports = function reporter(middlewareOptions, options) {
|
|
|
|
const { log, state, stats } = options;
|
|
|
|
|
|
|
|
if (state) {
|
|
|
|
const displayStats = middlewareOptions.stats !== false;
|
2024-01-16 21:26:16 +08:00
|
|
|
const statsString = stats.toString(middlewareOptions.stats);
|
2023-12-18 13:12:25 +08:00
|
|
|
|
2024-01-16 21:26:16 +08:00
|
|
|
// displayStats only logged
|
|
|
|
if (displayStats && statsString.trim().length) {
|
2023-12-18 13:12:25 +08:00
|
|
|
if (stats.hasErrors()) {
|
2024-01-16 21:26:16 +08:00
|
|
|
log.error(statsString);
|
2023-12-18 13:12:25 +08:00
|
|
|
} else if (stats.hasWarnings()) {
|
2024-01-16 21:26:16 +08:00
|
|
|
log.warn(statsString);
|
2023-12-18 13:12:25 +08:00
|
|
|
} else {
|
2024-01-16 21:26:16 +08:00
|
|
|
log.info(statsString);
|
2023-12-18 13:12:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let message = 'Compiled successfully.';
|
|
|
|
|
|
|
|
if (stats.hasErrors()) {
|
|
|
|
message = 'Failed to compile.';
|
|
|
|
} else if (stats.hasWarnings()) {
|
|
|
|
message = 'Compiled with warnings.';
|
|
|
|
}
|
|
|
|
log.info(message);
|
|
|
|
} else {
|
|
|
|
log.info('Compiling...');
|
|
|
|
}
|
|
|
|
};
|