|
| 1 | +const request = require('request'); |
| 2 | +const fs = require('fs'); |
| 3 | +const execSync = require('child_process').execSync; |
| 4 | +const CURRENT_VERSION = require('./lib/chromedriver').version; |
| 5 | + |
| 6 | +// fetch the latest chromedriver version |
| 7 | +const getLatest = (cb) => { |
| 8 | + request('https://chromedriver.storage.googleapis.com/LATEST_RELEASE', (err, response, body) => { |
| 9 | + if (err) { |
| 10 | + process.exit(1); |
| 11 | + } |
| 12 | + return cb(body); |
| 13 | + }); |
| 14 | +}; |
| 15 | + |
| 16 | +/* Provided a new Chromedriver version such as 77.0.3865.40: |
| 17 | + - update the version inside the ./lib/chromedriver helper file e.g. exports.version = '77.0.3865.40'; |
| 18 | + - bumps package.json version number |
| 19 | + - add a git tag using the new node-chromedriver version |
| 20 | + - add a git commit, e.g. Bump version to 77.0.0 |
| 21 | +*/ |
| 22 | +const writeUpdate = (version) => { |
| 23 | + const helper = fs.readFileSync('./lib/chromedriver.js', 'utf8'); |
| 24 | + const versionExport = 'exports.version'; |
| 25 | + const regex = new RegExp(`^.*${versionExport}.*$`, 'gm'); |
| 26 | + const updated = helper.replace(regex, `${versionExport} = '${version}';`); |
| 27 | + fs.writeFileSync('./lib/chromedriver.js', updated, 'utf8'); |
| 28 | + const packageVersion = `${version.slice(0, 2)}.0.0`; |
| 29 | + execSync(`npm version ${packageVersion} --git-tag-version=false && git add . && git commit -m "Bump version to ${packageVersion}" && git tag ${packageVersion}`); |
| 30 | +}; |
| 31 | + |
| 32 | +getLatest((version) => { |
| 33 | + if (CURRENT_VERSION === version) { |
| 34 | + console.log('Chromedriver version is up to date.'); |
| 35 | + } else { |
| 36 | + writeUpdate(version); |
| 37 | + console.log(`Chromedriver version updated to ${version}`); |
| 38 | + } |
| 39 | +}); |
0 commit comments