UNPKG

781 BJavaScriptView Raw
1const weblog = require('webpack-log');
2
3const WebpackCommandError = require('../WebpackCommandError');
4
5const Reporter = require('./Reporter');
6
7module.exports = class JsonReporter extends Reporter {
8 constructor(...args) {
9 super(...args);
10
11 const log = weblog({ name: 'webpack', id: 'webpack-command' });
12 this.originalLevel = log.level;
13 log.level = 'silent';
14 this.log = log;
15 }
16
17 /* istanbul ignore next */
18 progress() {
19 throw new WebpackCommandError(
20 'Build progress display is not supported when using the JSON reporter'
21 );
22 }
23
24 render(error, stats) {
25 const json = stats.toJson();
26 const result = JSON.stringify(json, null, 2);
27
28 process.stdout.write(result);
29
30 this.log.level = this.originalLevel;
31
32 return result;
33 }
34};