reporter.js 771 B

123456789101112131415161718192021222324252627282930
  1. 'use strict';
  2. module.exports = function reporter(middlewareOptions, options) {
  3. const { log, state, stats } = options;
  4. if (state) {
  5. const displayStats = middlewareOptions.stats !== false;
  6. if (displayStats) {
  7. if (stats.hasErrors()) {
  8. log.error(stats.toString(middlewareOptions.stats));
  9. } else if (stats.hasWarnings()) {
  10. log.warn(stats.toString(middlewareOptions.stats));
  11. } else {
  12. log.info(stats.toString(middlewareOptions.stats));
  13. }
  14. }
  15. let message = 'Compiled successfully.';
  16. if (stats.hasErrors()) {
  17. message = 'Failed to compile.';
  18. } else if (stats.hasWarnings()) {
  19. message = 'Compiled with warnings.';
  20. }
  21. log.info(message);
  22. } else {
  23. log.info('Compiling...');
  24. }
  25. };