| 
									
										
										
										
											2019-04-02 17:12:10 -07:00
										 |  |  | const cp = require('child_process') | 
					
						
							|  |  |  | const fs = require('fs-extra') | 
					
						
							|  |  |  | const os = require('os') | 
					
						
							| 
									
										
										
										
											2019-02-06 10:27:20 -08:00
										 |  |  | const path = require('path') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-02 17:12:10 -07:00
										 |  |  | const rootPath = path.resolve(__dirname, '..') | 
					
						
							| 
									
										
										
										
											2019-02-06 10:27:20 -08:00
										 |  |  | const gniPath = path.resolve(__dirname, '../filenames.auto.gni') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const allDocs = fs.readdirSync(path.resolve(__dirname, '../docs/api')) | 
					
						
							|  |  |  |   .map(doc => `docs/api/${doc}`) | 
					
						
							|  |  |  |   .concat( | 
					
						
							|  |  |  |     fs.readdirSync(path.resolve(__dirname, '../docs/api/structures')) | 
					
						
							|  |  |  |       .map(doc => `docs/api/structures/${doc}`) | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-02 17:12:10 -07:00
										 |  |  | const main = async () => { | 
					
						
							| 
									
										
										
										
											2019-06-02 13:03:03 -07:00
										 |  |  |   const webpackTargets = [ | 
					
						
							| 
									
										
										
										
											2019-04-02 17:12:10 -07:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-06-02 13:03:03 -07:00
										 |  |  |       name: 'sandbox_bundle_deps', | 
					
						
							|  |  |  |       config: 'webpack.config.sandboxed_renderer.js' | 
					
						
							| 
									
										
										
										
											2019-04-02 17:12:10 -07:00
										 |  |  |     }, | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-06-02 13:03:03 -07:00
										 |  |  |       name: 'isolated_bundle_deps', | 
					
						
							|  |  |  |       config: 'webpack.config.isolated_renderer.js' | 
					
						
							| 
									
										
										
										
											2019-04-02 17:12:10 -07:00
										 |  |  |     }, | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-06-02 13:03:03 -07:00
										 |  |  |       name: 'content_script_bundle_deps', | 
					
						
							|  |  |  |       config: 'webpack.config.content_script.js' | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       name: 'browser_bundle_deps', | 
					
						
							|  |  |  |       config: 'webpack.config.browser.js' | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       name: 'renderer_bundle_deps', | 
					
						
							|  |  |  |       config: 'webpack.config.renderer.js' | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       name: 'worker_bundle_deps', | 
					
						
							|  |  |  |       config: 'webpack.config.worker.js' | 
					
						
							| 
									
										
										
										
											2019-04-02 17:12:10 -07:00
										 |  |  |     } | 
					
						
							|  |  |  |   ] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-02 13:03:03 -07:00
										 |  |  |   await Promise.all(webpackTargets.map(async webpackTarget => { | 
					
						
							| 
									
										
										
										
											2019-04-02 17:12:10 -07:00
										 |  |  |     const tmpDir = await fs.mkdtemp(path.resolve(os.tmpdir(), 'electron-filenames-')) | 
					
						
							|  |  |  |     const child = cp.spawn('node', [ | 
					
						
							| 
									
										
										
										
											2019-06-02 13:03:03 -07:00
										 |  |  |       'build/webpack/get-outputs.js', | 
					
						
							|  |  |  |       `./${webpackTarget.config}`, | 
					
						
							|  |  |  |       path.resolve(tmpDir, `${webpackTarget.name}.measure.js`) | 
					
						
							| 
									
										
										
										
											2019-04-02 17:12:10 -07:00
										 |  |  |     ], { | 
					
						
							|  |  |  |       cwd: path.resolve(__dirname, '..') | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |     let output = '' | 
					
						
							|  |  |  |     child.stdout.on('data', chunk => { | 
					
						
							|  |  |  |       output += chunk.toString() | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2019-05-06 08:29:01 -07:00
										 |  |  |     child.stderr.on('data', chunk => console.error(chunk.toString())) | 
					
						
							| 
									
										
										
										
											2019-04-02 17:12:10 -07:00
										 |  |  |     await new Promise((resolve, reject) => child.on('exit', (code) => { | 
					
						
							| 
									
										
										
										
											2019-05-06 08:29:01 -07:00
										 |  |  |       if (code !== 0) { | 
					
						
							|  |  |  |         console.error(output) | 
					
						
							| 
									
										
										
										
											2019-06-02 13:03:03 -07:00
										 |  |  |         return reject(new Error(`Failed to list webpack dependencies for entry: ${webpackTarget.name}`)) | 
					
						
							| 
									
										
										
										
											2019-05-06 08:29:01 -07:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-02 17:12:10 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       resolve() | 
					
						
							|  |  |  |     })) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-02 13:03:03 -07:00
										 |  |  |     webpackTarget.dependencies = JSON.parse(output) | 
					
						
							| 
									
										
										
										
											2019-04-02 17:12:10 -07:00
										 |  |  |       // Remove whitespace
 | 
					
						
							|  |  |  |       .map(line => line.trim()) | 
					
						
							|  |  |  |       // Get the relative path
 | 
					
						
							| 
									
										
										
										
											2019-06-03 11:43:55 -07:00
										 |  |  |       .map(line => path.relative(rootPath, line).replace(/\\/g, '/')) | 
					
						
							| 
									
										
										
										
											2019-04-02 17:12:10 -07:00
										 |  |  |       // Only care about files in //electron
 | 
					
						
							|  |  |  |       .filter(line => !line.startsWith('..')) | 
					
						
							|  |  |  |       // Only care about our own files
 | 
					
						
							|  |  |  |       .filter(line => !line.startsWith('node_modules')) | 
					
						
							| 
									
										
										
										
											2019-06-02 13:03:03 -07:00
										 |  |  |       // All webpack builds depend on the tsconfig  and package json files
 | 
					
						
							|  |  |  |       .concat(['tsconfig.json', 'tsconfig.electron.json', 'package.json']) | 
					
						
							| 
									
										
										
										
											2019-04-02 17:12:10 -07:00
										 |  |  |       // Make the generated list easier to read
 | 
					
						
							|  |  |  |       .sort() | 
					
						
							|  |  |  |     await fs.remove(tmpDir) | 
					
						
							|  |  |  |   })) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   fs.writeFileSync( | 
					
						
							|  |  |  |     gniPath, | 
					
						
							|  |  |  |     `# THIS FILE IS AUTO-GENERATED, PLEASE DO NOT EDIT BY HAND
 | 
					
						
							| 
									
										
										
										
											2019-02-06 10:27:20 -08:00
										 |  |  | auto_filenames = { | 
					
						
							|  |  |  |   api_docs = [ | 
					
						
							|  |  |  | ${allDocs.map(doc => `    "${doc}",`).join('\n')} | 
					
						
							|  |  |  |   ] | 
					
						
							| 
									
										
										
										
											2019-04-02 17:12:10 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-02 13:03:03 -07:00
										 |  |  | ${webpackTargets.map(target => `  ${target.name} = [
 | 
					
						
							| 
									
										
										
										
											2019-04-02 17:12:10 -07:00
										 |  |  | ${target.dependencies.map(dep => `    "${dep}",`).join('\n')} | 
					
						
							|  |  |  |   ]`).join('\n\n')}
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | `)
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if (process.mainModule === module) { | 
					
						
							|  |  |  |   main().catch((err) => { | 
					
						
							|  |  |  |     console.error(err) | 
					
						
							|  |  |  |     process.exit(1) | 
					
						
							|  |  |  |   }) | 
					
						
							| 
									
										
										
										
											2019-02-06 10:27:20 -08:00
										 |  |  | } |