1 | const weblog = require('webpack-log');
|
2 |
|
3 | const WebpackCommandError = require('../WebpackCommandError');
|
4 |
|
5 | const Reporter = require('./Reporter');
|
6 |
|
7 | module.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 |
|
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 | if (error) {
|
26 | return error;
|
27 | }
|
28 |
|
29 | const json = stats.toJson();
|
30 | const result = JSON.stringify(json, null, 2);
|
31 |
|
32 | process.stdout.write(result);
|
33 |
|
34 | this.log.level = this.originalLevel;
|
35 |
|
36 | return result;
|
37 | }
|
38 | };
|