forked from giggio/node-chromedriver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.js
39 lines (36 loc) · 1.52 KB
/
update.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
const request = require('request');
const fs = require('fs');
const execSync = require('child_process').execSync;
const CURRENT_VERSION = require('./lib/chromedriver').version;
// fetch the latest chromedriver version
const getLatest = (cb) => {
request('https://chromedriver.storage.googleapis.com/LATEST_RELEASE', (err, response, body) => {
if (err) {
process.exit(1);
}
return cb(body);
});
};
/* Provided a new Chromedriver version such as 77.0.3865.40:
- update the version inside the ./lib/chromedriver helper file e.g. exports.version = '77.0.3865.40';
- bumps package.json version number
- add a git tag using the new node-chromedriver version
- add a git commit, e.g. Bump version to 77.0.0
*/
const writeUpdate = (version) => {
const helper = fs.readFileSync('./lib/chromedriver.js', 'utf8');
const versionExport = 'exports.version';
const regex = new RegExp(`^.*${versionExport}.*$`, 'gm');
const updated = helper.replace(regex, `${versionExport} = '${version}';`);
fs.writeFileSync('./lib/chromedriver.js', updated, 'utf8');
const packageVersion = `${version.slice(0, 2)}.0.0`;
execSync(`npm version ${packageVersion} --git-tag-version=false && git add . && git commit -m "Bump version to ${packageVersion}" && git tag -s ${packageVersion} -m ${packageVersion}`);
};
getLatest((version) => {
if (CURRENT_VERSION === version) {
console.log('Chromedriver version is up to date.');
} else {
writeUpdate(version);
console.log(`Chromedriver version updated to ${version}`);
}
});