| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | const Stats = require("./Stats"); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | const optionOrFallback = (optionValue, fallbackValue) => | 
					
						
							|  |  |  | 	optionValue !== undefined ? optionValue : fallbackValue; | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | class MultiStats { | 
					
						
							|  |  |  | 	constructor(stats) { | 
					
						
							|  |  |  | 		this.stats = stats; | 
					
						
							|  |  |  | 		this.hash = stats.map(stat => stat.hash).join(""); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | 	hasErrors() { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		return this.stats | 
					
						
							|  |  |  | 			.map(stat => stat.hasErrors()) | 
					
						
							|  |  |  | 			.reduce((a, b) => a || b, false); | 
					
						
							| 
									
										
										
										
											2017-01-11 17:51:58 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	hasWarnings() { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		return this.stats | 
					
						
							|  |  |  | 			.map(stat => stat.hasWarnings()) | 
					
						
							|  |  |  | 			.reduce((a, b) => a || b, false); | 
					
						
							| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	toJson(options, forToString) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (typeof options === "boolean" || typeof options === "string") { | 
					
						
							| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | 			options = Stats.presetToOptions(options); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		} else if (!options) { | 
					
						
							| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | 			options = {}; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		const jsons = this.stats.map((stat, idx) => { | 
					
						
							|  |  |  | 			const childOptions = Stats.getChildOptions(options, idx); | 
					
						
							|  |  |  | 			const obj = stat.toJson(childOptions, forToString); | 
					
						
							|  |  |  | 			obj.name = stat.compilation && stat.compilation.name; | 
					
						
							|  |  |  | 			return obj; | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		const showVersion = | 
					
						
							| 
									
										
										
										
											2018-08-21 08:26:50 +08:00
										 |  |  | 			options.version === undefined | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				? jsons.every(j => j.version) | 
					
						
							|  |  |  | 				: options.version !== false; | 
					
						
							|  |  |  | 		const showHash = | 
					
						
							| 
									
										
										
										
											2018-08-21 08:26:50 +08:00
										 |  |  | 			options.hash === undefined | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				? jsons.every(j => j.hash) | 
					
						
							|  |  |  | 				: options.hash !== false; | 
					
						
							|  |  |  | 		if (showVersion) { | 
					
						
							|  |  |  | 			for (const j of jsons) { | 
					
						
							| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | 				delete j.version; | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | 		const obj = { | 
					
						
							|  |  |  | 			errors: jsons.reduce((arr, j) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				return arr.concat( | 
					
						
							|  |  |  | 					j.errors.map(msg => { | 
					
						
							|  |  |  | 						return `(${j.name}) ${msg}`; | 
					
						
							|  |  |  | 					}) | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | 			}, []), | 
					
						
							|  |  |  | 			warnings: jsons.reduce((arr, j) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				return arr.concat( | 
					
						
							|  |  |  | 					j.warnings.map(msg => { | 
					
						
							|  |  |  | 						return `(${j.name}) ${msg}`; | 
					
						
							|  |  |  | 					}) | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | 			}, []) | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (showVersion) obj.version = require("../package.json").version; | 
					
						
							|  |  |  | 		if (showHash) obj.hash = this.hash; | 
					
						
							|  |  |  | 		if (options.children !== false) obj.children = jsons; | 
					
						
							| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | 		return obj; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	toString(options) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (typeof options === "boolean" || typeof options === "string") { | 
					
						
							| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | 			options = Stats.presetToOptions(options); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		} else if (!options) { | 
					
						
							| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | 			options = {}; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 05:04:35 +08:00
										 |  |  | 		const useColors = optionOrFallback(options.colors, false); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | 		const obj = this.toJson(options, true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return Stats.jsonToString(obj, useColors); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | module.exports = MultiStats; |