| 
									
										
										
										
											2012-03-12 04:50:55 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2012-03-10 20:11:23 +08:00
										 |  |  | var writeSource = require("./writeSource"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-12 22:43:37 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * return the content of a chunk: | 
					
						
							|  |  |  |  * [id]: function(...) { | 
					
						
							|  |  |  |  *    [source] | 
					
						
							|  |  |  |  * }, | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2012-03-10 20:11:23 +08:00
										 |  |  | module.exports = function(depTree, chunk, options) { | 
					
						
							|  |  |  | 	if(!options) { | 
					
						
							|  |  |  | 		options = chunk; | 
					
						
							|  |  |  | 		chunk = null; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	var buffer = []; | 
					
						
							| 
									
										
										
										
											2012-03-15 07:05:29 +08:00
										 |  |  | 	var modules = chunk ? chunk.modules : depTree.modules; | 
					
						
							| 
									
										
										
										
											2012-04-08 03:36:55 +08:00
										 |  |  | 	var includedModules = []; | 
					
						
							| 
									
										
										
										
											2012-03-10 20:11:23 +08:00
										 |  |  | 	for(var moduleId in modules) { | 
					
						
							|  |  |  | 		if(chunk) { | 
					
						
							|  |  |  | 			if(chunk.modules[moduleId] !== "include") | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-03-15 07:05:29 +08:00
										 |  |  | 		var module = depTree.modules[moduleId]; | 
					
						
							| 
									
										
										
										
											2012-04-08 03:36:55 +08:00
										 |  |  | 		includedModules.push(module); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	includedModules.sort(function(a, b) { return a.realId - b.realId; }); | 
					
						
							|  |  |  | 	includedModules.forEach(function(module) { | 
					
						
							| 
									
										
										
										
											2012-03-10 20:11:23 +08:00
										 |  |  | 		buffer.push("/******/"); | 
					
						
							| 
									
										
										
										
											2012-04-08 03:36:55 +08:00
										 |  |  | 		buffer.push(module.realId); | 
					
						
							| 
									
										
										
										
											2012-03-10 20:11:23 +08:00
										 |  |  | 		buffer.push(": function(module, exports, require) {\n\n"); | 
					
						
							|  |  |  | 		if(options.includeFilenames) { | 
					
						
							|  |  |  | 			buffer.push("/*** "); | 
					
						
							|  |  |  | 			buffer.push(module.filename); | 
					
						
							|  |  |  | 			buffer.push(" ***/\n\n"); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-04-08 03:36:55 +08:00
										 |  |  | 		buffer.push(writeSource(module, options, function(id) { return depTree.modules[id].realId })); | 
					
						
							| 
									
										
										
										
											2012-03-10 20:11:23 +08:00
										 |  |  | 		buffer.push("\n\n/******/},\n/******/\n"); | 
					
						
							| 
									
										
										
										
											2012-04-08 03:36:55 +08:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2012-03-10 20:11:23 +08:00
										 |  |  | 	return buffer.join(""); | 
					
						
							|  |  |  | } |