| 
									
										
										
										
											2012-04-05 20:59:01 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2017-07-27 19:24:56 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2012-04-05 20:59:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-27 19:24:56 +08:00
										 |  |  | const cp = require("child_process"); | 
					
						
							|  |  |  | const path = require("path"); | 
					
						
							|  |  |  | const tc = require("./template-common"); | 
					
						
							|  |  |  | const fs = require("fs"); | 
					
						
							| 
									
										
										
										
											2012-04-05 20:59:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-27 19:24:56 +08:00
										 |  |  | const extraArgs = ""; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-21 18:04:18 +08:00
										 |  |  | const hasConfiguration = fs.existsSync("webpack.config.js"); | 
					
						
							|  |  |  | const targetArgs = global.NO_TARGET_ARGS ? "" : " ./example.js js/output.js "; | 
					
						
							| 
									
										
										
										
											2017-07-27 19:24:56 +08:00
										 |  |  | const displayReasons = global.NO_REASONS ? "" : " --display-reasons --display-used-exports --display-provided-exports"; | 
					
						
							| 
									
										
										
										
											2017-11-21 18:04:18 +08:00
										 |  |  | const modeArgs = hasConfiguration ? "" : "--mode production"; | 
					
						
							|  |  |  | cp.exec(`node ${path.resolve(__dirname, "../bin/webpack.js")} ${modeArgs} ${displayReasons} --display-chunks --display-max-modules 99999 --display-origins --display-entrypoints --output-public-path "js/" -p ${extraArgs} ${targetArgs}`, function(error, stdout, stderr) { | 
					
						
							| 
									
										
										
										
											2017-06-05 22:12:12 +08:00
										 |  |  | 	if(stderr) | 
					
						
							|  |  |  | 		console.log(stderr); | 
					
						
							|  |  |  | 	if(error !== null) | 
					
						
							|  |  |  | 		console.log(error); | 
					
						
							| 
									
										
										
										
											2017-07-27 19:24:56 +08:00
										 |  |  | 	let readme; | 
					
						
							| 
									
										
										
										
											2017-06-05 22:12:12 +08:00
										 |  |  | 	try { | 
					
						
							| 
									
										
										
										
											2017-07-27 19:24:56 +08:00
										 |  |  | 		readme = tc.replaceResults(fs.readFileSync(require("path").join(process.cwd(), "template.md"), "utf-8"), process.cwd(), stdout.replace(/[\r\n]*$/, ""), "min"); | 
					
						
							| 
									
										
										
										
											2017-06-05 22:12:12 +08:00
										 |  |  | 	} catch(e) { | 
					
						
							|  |  |  | 		console.log(stderr); | 
					
						
							|  |  |  | 		throw e; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-21 18:04:18 +08:00
										 |  |  | 	cp.exec(`node ${path.resolve(__dirname, "../bin/webpack.js")} ${modeArgs} ${displayReasons} --display-chunks --display-max-modules 99999 --display-origins --display-entrypoints --output-public-path "js/" --output-pathinfo ${extraArgs} ${targetArgs}`, function(error, stdout, stderr) { | 
					
						
							| 
									
										
										
										
											2017-06-05 22:12:12 +08:00
										 |  |  | 		console.log(stdout); | 
					
						
							|  |  |  | 		if(stderr) | 
					
						
							| 
									
										
										
										
											2012-04-05 20:59:01 +08:00
										 |  |  | 			console.log(stderr); | 
					
						
							| 
									
										
										
										
											2017-06-05 22:12:12 +08:00
										 |  |  | 		if(error !== null) | 
					
						
							| 
									
										
										
										
											2012-04-05 20:59:01 +08:00
										 |  |  | 			console.log(error); | 
					
						
							| 
									
										
										
										
											2017-06-05 22:12:12 +08:00
										 |  |  | 		readme = tc.replaceResults(readme, process.cwd(), stdout.replace(/[\r\n]*$/, "")); | 
					
						
							|  |  |  | 		readme = tc.replaceBase(readme); | 
					
						
							|  |  |  | 		fs.writeFile("README.md", readme, "utf-8", function() {}); | 
					
						
							| 
									
										
										
										
											2012-04-05 20:59:01 +08:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2017-06-05 22:12:12 +08:00
										 |  |  | }); |