|
2 | 2 | MIT License http://www.opensource.org/licenses/mit-license.php |
3 | 3 | Author Tobias Koppers @sokra |
4 | 4 | */ |
5 | | -var Stats = require("./Stats"); |
| 5 | +"use strict"; |
6 | 6 |
|
7 | | -function MultiStats(stats) { |
8 | | - this.stats = stats; |
9 | | - this.hash = stats.map(function(stat) { |
10 | | - return stat.hash; |
11 | | - }).join(""); |
12 | | -} |
| 7 | +const Stats = require("./Stats"); |
13 | 8 |
|
14 | | -MultiStats.prototype.hasErrors = function() { |
15 | | - return this.stats.map(function(stat) { |
16 | | - return stat.hasErrors(); |
17 | | - }).reduce(function(a, b) { |
18 | | - return a || b; |
19 | | - }, false); |
20 | | -}; |
| 9 | +const optionOrFallback = (optionValue, fallbackValue) => optionValue !== undefined ? optionValue : fallbackValue; |
21 | 10 |
|
22 | | -MultiStats.prototype.hasWarnings = function() { |
23 | | - return this.stats.map(function(stat) { |
24 | | - return stat.hasWarnings(); |
25 | | - }).reduce(function(a, b) { |
26 | | - return a || b; |
27 | | - }, false); |
28 | | -}; |
| 11 | +class MultiStats { |
| 12 | + constructor(stats) { |
| 13 | + this.stats = stats; |
| 14 | + this.hash = stats.map((stat) => stat.hash).join(""); |
| 15 | + } |
29 | 16 |
|
30 | | -MultiStats.prototype.toJson = function(options, forToString) { |
31 | | - if(typeof options === "boolean" || typeof options === "string") { |
32 | | - options = Stats.presetToOptions(options); |
33 | | - } else if(!options) { |
34 | | - options = {}; |
| 17 | + hasErrors() { |
| 18 | + return this.stats.map((stat) => stat.hasErrors()).reduce((a, b) => a || b, false); |
35 | 19 | } |
36 | | - var jsons = this.stats.map((stat, idx) => { |
37 | | - var childOptions = Stats.getChildOptions(options, idx); |
38 | | - var obj = stat.toJson(childOptions, forToString); |
39 | | - obj.name = stat.compilation && stat.compilation.name; |
40 | | - return obj; |
41 | | - }); |
42 | | - var showVersion = typeof options.version === "undefined" ? jsons.every(j => j.version) : options.version !== false; |
43 | | - var showHash = typeof options.hash === "undefined" ? jsons.every(j => j.hash) : options.hash !== false; |
44 | | - jsons.forEach(j => { |
| 20 | + |
| 21 | + hasWarnings() { |
| 22 | + return this.stats.map((stat) => stat.hasWarnings()).reduce((a, b) => a || b, false); |
| 23 | + } |
| 24 | + |
| 25 | + toJson(options, forToString) { |
| 26 | + if(typeof options === "boolean" || typeof options === "string") { |
| 27 | + options = Stats.presetToOptions(options); |
| 28 | + } else if(!options) { |
| 29 | + options = {}; |
| 30 | + } |
| 31 | + const jsons = this.stats.map((stat, idx) => { |
| 32 | + const childOptions = Stats.getChildOptions(options, idx); |
| 33 | + const obj = stat.toJson(childOptions, forToString); |
| 34 | + obj.name = stat.compilation && stat.compilation.name; |
| 35 | + return obj; |
| 36 | + }); |
| 37 | + const showVersion = typeof options.version === "undefined" ? jsons.every(j => j.version) : options.version !== false; |
| 38 | + const showHash = typeof options.hash === "undefined" ? jsons.every(j => j.hash) : options.hash !== false; |
| 39 | + jsons.forEach(j => { |
| 40 | + if(showVersion) |
| 41 | + delete j.version; |
| 42 | + }); |
| 43 | + const obj = { |
| 44 | + errors: jsons.reduce((arr, j) => { |
| 45 | + return arr.concat(j.errors.map((msg) => { |
| 46 | + return `(${j.name}) ${msg}`; |
| 47 | + })); |
| 48 | + }, []), |
| 49 | + warnings: jsons.reduce((arr, j) => { |
| 50 | + return arr.concat(j.warnings.map((msg) => { |
| 51 | + return `(${j.name}) ${msg}`; |
| 52 | + })); |
| 53 | + }, []) |
| 54 | + }; |
45 | 55 | if(showVersion) |
46 | | - delete j.version; |
47 | | - }); |
48 | | - var obj = { |
49 | | - errors: jsons.reduce(function(arr, j) { |
50 | | - return arr.concat(j.errors.map(function(msg) { |
51 | | - return "(" + j.name + ") " + msg; |
52 | | - })); |
53 | | - }, []), |
54 | | - warnings: jsons.reduce(function(arr, j) { |
55 | | - return arr.concat(j.warnings.map(function(msg) { |
56 | | - return "(" + j.name + ") " + msg; |
57 | | - })); |
58 | | - }, []) |
59 | | - }; |
60 | | - if(showVersion) |
61 | | - obj.version = require("../package.json").version; |
62 | | - if(showHash) |
63 | | - obj.hash = this.hash; |
64 | | - if(options.children !== false) |
65 | | - obj.children = jsons; |
66 | | - return obj; |
67 | | -}; |
| 56 | + obj.version = require("../package.json").version; |
| 57 | + if(showHash) |
| 58 | + obj.hash = this.hash; |
| 59 | + if(options.children !== false) |
| 60 | + obj.children = jsons; |
| 61 | + return obj; |
| 62 | + } |
| 63 | + |
| 64 | + toString(options) { |
| 65 | + if(typeof options === "boolean" || typeof options === "string") { |
| 66 | + options = Stats.presetToOptions(options); |
| 67 | + } else if(!options) { |
| 68 | + options = {}; |
| 69 | + } |
| 70 | + |
| 71 | + const useColors = optionOrFallback(options.colors, false); |
68 | 72 |
|
69 | | -MultiStats.prototype.toString = Stats.prototype.toString; |
| 73 | + const obj = this.toJson(options, true); |
| 74 | + |
| 75 | + return Stats.jsonToString(obj, useColors); |
| 76 | + } |
| 77 | +} |
70 | 78 |
|
71 | 79 | module.exports = MultiStats; |
0 commit comments