-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
roll_browser.js
executable file
·90 lines (79 loc) · 3.2 KB
/
roll_browser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env node
/**
* 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');
const fs = require('fs');
const protocolGenerator = require('./protocol-types-generator');
const {execSync} = require('child_process');
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.
Supported browsers: chromium, firefox, webkit.
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);
}
const browserName = args[0].toLowerCase();
if (!['chromium', 'firefox', 'webkit', 'ffmpeg'].includes(browserName)) {
console.log(`Unknown browser "${browserName}"`);
console.log(`Try running ${SCRIPT_NAME} --help`);
process.exit(1);
}
const revision = args[1];
console.log(`Rolling ${browserName} to ${revision}`);
// 2. Update browsers.json.
console.log('\nUpdating browsers.json...');
const browsersJSON = require(path.join(ROOT_PATH, 'browsers.json'));
browsersJSON.browsers.find(b => b.name === browserName).revision = String(revision);
fs.writeFileSync(path.join(ROOT_PATH, 'browsers.json'), JSON.stringify(browsersJSON, null, 2) + '\n');
// 3. Download new browser.
console.log('\nDownloading new browser...');
const { installBrowsersWithProgressBar } = require('../lib/install/installer');
await installBrowsersWithProgressBar(ROOT_PATH);
// 4. Generate types.
console.log('\nGenerating protocol types...');
const browser = { name: browserName, revision };
const browserPaths = require('../lib/utils/browserPaths');
const browserDir = browserPaths.browserDirectory(browserPaths.browsersPath(ROOT_PATH), browser);
const executablePath = browserPaths.executablePath(browserDir, browser);
await protocolGenerator.generateProtocol(browserName, executablePath).catch(console.warn);
// 5. Update docs.
console.log('\nUpdating documentation...');
try {
process.stdout.write(execSync('npm run --silent doc'));
} catch (e) {
}
console.log(`\nRolled ${browserName} to ${revision}`);
})();