| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 05:04:35 +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() { | 
					
						
							| 
									
										
										
										
											2017-03-05 05:04:35 +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() { | 
					
						
							| 
									
										
										
										
											2017-03-05 05:04:35 +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) { | 
					
						
							|  |  |  | 		if(typeof options === "boolean" || typeof options === "string") { | 
					
						
							|  |  |  | 			options = Stats.presetToOptions(options); | 
					
						
							|  |  |  | 		} else if(!options) { | 
					
						
							|  |  |  | 			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; | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-03-05 05:04:35 +08:00
										 |  |  | 		const showVersion = typeof options.version === "undefined" ? jsons.every(j => j.version) : options.version !== false; | 
					
						
							|  |  |  | 		const showHash = typeof options.hash === "undefined" ? jsons.every(j => j.hash) : options.hash !== false; | 
					
						
							| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | 		jsons.forEach(j => { | 
					
						
							|  |  |  | 			if(showVersion) | 
					
						
							|  |  |  | 				delete j.version; | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		const obj = { | 
					
						
							|  |  |  | 			errors: jsons.reduce((arr, j) => { | 
					
						
							|  |  |  | 				return arr.concat(j.errors.map(msg => { | 
					
						
							| 
									
										
										
										
											2017-03-05 05:04:35 +08:00
										 |  |  | 					return `(${j.name}) ${msg}`; | 
					
						
							| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | 				})); | 
					
						
							|  |  |  | 			}, []), | 
					
						
							|  |  |  | 			warnings: jsons.reduce((arr, j) => { | 
					
						
							|  |  |  | 				return arr.concat(j.warnings.map(msg => { | 
					
						
							| 
									
										
										
										
											2017-03-05 05:04:35 +08:00
										 |  |  | 					return `(${j.name}) ${msg}`; | 
					
						
							| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | 				})); | 
					
						
							|  |  |  | 			}, []) | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2017-01-11 17:51:58 +08:00
										 |  |  | 		if(showVersion) | 
					
						
							| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | 			obj.version = require("../package.json").version; | 
					
						
							|  |  |  | 		if(showHash) | 
					
						
							|  |  |  | 			obj.hash = this.hash; | 
					
						
							|  |  |  | 		if(options.children !== false) | 
					
						
							|  |  |  | 			obj.children = jsons; | 
					
						
							|  |  |  | 		return obj; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	toString(options) { | 
					
						
							|  |  |  | 		if(typeof options === "boolean" || typeof options === "string") { | 
					
						
							|  |  |  | 			options = Stats.presetToOptions(options); | 
					
						
							|  |  |  | 		} else if(!options) { | 
					
						
							|  |  |  | 			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; |