| 
									
										
										
										
											2016-10-04 20:39:20 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							|  |  |  |  * Copyright Google Inc. All Rights Reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-18 15:08:49 +01:00
										 |  |  | var webpack = require('webpack'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Wraps the original `webpack` function to convert execution | 
					
						
							|  |  |  |  * result to a promise and properly report errors. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @param options | 
					
						
							|  |  |  |  * @returns {Function} | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | function webPackPromiseify(options) { | 
					
						
							| 
									
										
										
										
											2016-10-04 20:39:20 -07:00
										 |  |  |   return new Promise(function(resolve, reject) { | 
					
						
							| 
									
										
										
										
											2016-01-18 15:08:49 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     webpack(options, function(err, stats) { | 
					
						
							|  |  |  |       var jsonStats = stats.toJson() || {}; | 
					
						
							|  |  |  |       var statsErrors = jsonStats.errors || []; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (err) { | 
					
						
							|  |  |  |         return reject(err); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (statsErrors.length) { | 
					
						
							|  |  |  |         return reject(statsErrors); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       return resolve(stats); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-04 20:39:20 -07:00
										 |  |  | module.exports = webPackPromiseify; |