| 
									
										
										
										
											2020-07-02 00:40:47 -07:00
										 |  |  | #!/usr/bin/env node
 | 
					
						
							| 
									
										
										
										
											2020-07-01 15:22:29 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Copyright 2017 Google Inc. All rights reserved. | 
					
						
							|  |  |  |  * Modifications copyright (c) Microsoft Corporation. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
					
						
							|  |  |  |  * you may not use this file except in compliance with the License. | 
					
						
							|  |  |  |  * You may obtain a copy of the License at | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *     http://www.apache.org/licenses/LICENSE-2.0
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Unless required by applicable law or agreed to in writing, software | 
					
						
							|  |  |  |  * distributed under the License is distributed on an "AS IS" BASIS, | 
					
						
							|  |  |  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
					
						
							|  |  |  |  * See the License for the specific language governing permissions and | 
					
						
							|  |  |  |  * limitations under the License. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const path = require('path'); | 
					
						
							| 
									
										
										
										
											2021-02-08 16:02:49 -08:00
										 |  |  | const {Registry} = require('../lib/utils/registry'); | 
					
						
							| 
									
										
										
										
											2020-07-01 15:22:29 -07:00
										 |  |  | const fs = require('fs'); | 
					
						
							|  |  |  | const protocolGenerator = require('./protocol-types-generator'); | 
					
						
							| 
									
										
										
										
											2020-07-22 11:03:35 -07:00
										 |  |  | const {execSync} = require('child_process'); | 
					
						
							| 
									
										
										
										
											2020-07-01 15:22:29 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | const SCRIPT_NAME = path.basename(__filename); | 
					
						
							|  |  |  | const ROOT_PATH = path.resolve(path.join(__dirname, '..')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function usage() { | 
					
						
							|  |  |  |   return `
 | 
					
						
							|  |  |  | usage: ${SCRIPT_NAME} <browser> <revision> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Roll the <browser> to a specific <revision> and generate new protocol. | 
					
						
							| 
									
										
										
										
											2021-06-15 23:58:30 -07:00
										 |  |  | Supported browsers: chromium, firefox, webkit, ffmpeg, firefox-beta. | 
					
						
							| 
									
										
										
										
											2020-07-01 15:22:29 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | Example: | 
					
						
							|  |  |  |   ${SCRIPT_NAME} chromium 123456 | 
					
						
							|  |  |  | `;
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | (async () => { | 
					
						
							|  |  |  |   // 1. Parse CLI arguments
 | 
					
						
							|  |  |  |   const args = process.argv.slice(2); | 
					
						
							|  |  |  |   if (args.some(arg => arg === '--help')) { | 
					
						
							|  |  |  |     console.log(usage()); | 
					
						
							|  |  |  |     process.exit(1); | 
					
						
							|  |  |  |   } else if (args.length < 1) { | 
					
						
							|  |  |  |     console.log(`Please specify the browser name, e.g. 'chromium'.`); | 
					
						
							|  |  |  |     console.log(`Try running ${SCRIPT_NAME} --help`); | 
					
						
							|  |  |  |     process.exit(1); | 
					
						
							|  |  |  |   } else if (args.length < 2) { | 
					
						
							|  |  |  |     console.log(`Please specify the revision`); | 
					
						
							|  |  |  |     console.log(`Try running ${SCRIPT_NAME} --help`); | 
					
						
							|  |  |  |     process.exit(1); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-04-22 19:45:34 -05:00
										 |  |  |   const browsersJSON = require(path.join(ROOT_PATH, 'browsers.json')); | 
					
						
							| 
									
										
										
										
											2020-07-01 15:22:29 -07:00
										 |  |  |   const browserName = args[0].toLowerCase(); | 
					
						
							| 
									
										
										
										
											2021-04-22 19:45:34 -05:00
										 |  |  |   const descriptor = browsersJSON.browsers.find(b => b.name === browserName); | 
					
						
							|  |  |  |   if (!descriptor) { | 
					
						
							| 
									
										
										
										
											2020-07-01 15:22:29 -07:00
										 |  |  |     console.log(`Unknown browser "${browserName}"`); | 
					
						
							|  |  |  |     console.log(`Try running ${SCRIPT_NAME} --help`); | 
					
						
							|  |  |  |     process.exit(1); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   const revision = args[1]; | 
					
						
							| 
									
										
										
										
											2020-07-22 11:03:35 -07:00
										 |  |  |   console.log(`Rolling ${browserName} to ${revision}`); | 
					
						
							| 
									
										
										
										
											2020-07-01 15:22:29 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // 2. Update browsers.json.
 | 
					
						
							| 
									
										
										
										
											2020-07-22 11:03:35 -07:00
										 |  |  |   console.log('\nUpdating browsers.json...'); | 
					
						
							| 
									
										
										
										
											2021-04-22 19:45:34 -05:00
										 |  |  |   descriptor.revision = String(revision); | 
					
						
							| 
									
										
										
										
											2021-06-15 17:57:31 -07:00
										 |  |  |   if (browserName === 'chromium') | 
					
						
							|  |  |  |     browsersJSON.browsers.find(b => b.name === 'chromium-with-symbols').revision = String(revision); | 
					
						
							| 
									
										
										
										
											2020-07-01 15:22:29 -07:00
										 |  |  |   fs.writeFileSync(path.join(ROOT_PATH, 'browsers.json'), JSON.stringify(browsersJSON, null, 2) + '\n'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-22 19:45:34 -05:00
										 |  |  |   if (descriptor.installByDefault) { | 
					
						
							|  |  |  |     // 3. Download new browser.
 | 
					
						
							|  |  |  |     console.log('\nDownloading new browser...'); | 
					
						
							| 
									
										
										
										
											2021-07-14 18:39:39 -07:00
										 |  |  |     const registry = new Registry(ROOT_PATH); | 
					
						
							|  |  |  |     await registry.install(); | 
					
						
							| 
									
										
										
										
											2020-07-01 15:22:29 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-22 19:45:34 -05:00
										 |  |  |     // 4. Generate types.
 | 
					
						
							|  |  |  |     console.log('\nGenerating protocol types...'); | 
					
						
							| 
									
										
										
										
											2021-07-14 18:39:39 -07:00
										 |  |  |     const executablePath = registry.findExecutable(browserName).executablePathOrDie(); | 
					
						
							| 
									
										
										
										
											2021-04-22 19:45:34 -05:00
										 |  |  |     await protocolGenerator.generateProtocol(browserName, executablePath).catch(console.warn); | 
					
						
							| 
									
										
										
										
											2020-07-22 11:03:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-22 19:45:34 -05:00
										 |  |  |     // 5. Update docs.
 | 
					
						
							|  |  |  |     console.log('\nUpdating documentation...'); | 
					
						
							|  |  |  |     try { | 
					
						
							|  |  |  |       process.stdout.write(execSync('npm run --silent doc')); | 
					
						
							|  |  |  |     } catch (e) { | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-07-22 11:03:35 -07:00
										 |  |  |   } | 
					
						
							|  |  |  |   console.log(`\nRolled ${browserName} to ${revision}`); | 
					
						
							| 
									
										
										
										
											2020-07-01 15:22:29 -07:00
										 |  |  | })(); |