Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from erickzhao/chore/migrate-get
chore: upgrade dependencies to latest
- Loading branch information
Showing
5 changed files
with
528 additions
and
779 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,40 @@ | ||
const fs = require('fs') | ||
const { promises: fs } = require('fs') | ||
const path = require('path') | ||
const electronDownload = require('electron-download') | ||
const { downloadArtifact } = require('@electron/get') | ||
const extractZip = require('extract-zip') | ||
const versionToDownload = require('./package').version | ||
|
||
function download (version, callback) { | ||
electronDownload({ | ||
function download (version) { | ||
return downloadArtifact({ | ||
version, | ||
chromedriver: true, | ||
artifactName: 'chromedriver', | ||
platform: process.env.npm_config_platform, | ||
arch: process.env.npm_config_arch, | ||
strictSSL: process.env.npm_config_strict_ssl === 'true', | ||
rejectUnauthorized: process.env.npm_config_strict_ssl === 'true', | ||
quiet: ['info', 'verbose', 'silly', 'http'].indexOf(process.env.npm_config_loglevel) === -1 | ||
}, callback) | ||
}) | ||
} | ||
|
||
function processDownload (err, zipPath) { | ||
if (err != null) throw err | ||
extractZip(zipPath, { dir: path.join(__dirname, 'bin') }, error => { | ||
if (error != null) throw error | ||
async function attemptDownload (version) { | ||
try { | ||
const targetFolder = path.join(__dirname, 'bin') | ||
const zipPath = await download(version) | ||
await extractZip(zipPath, { dir: targetFolder }) | ||
if (process.platform !== 'win32') { | ||
fs.chmod(path.join(__dirname, 'bin', 'chromedriver'), '755', error => { | ||
if (error != null) throw error | ||
}) | ||
await fs.chmod(path.join(targetFolder, 'chromedriver'), 0o755) | ||
} | ||
}) | ||
} | ||
|
||
download(versionToDownload, (err, zipPath) => { | ||
if (err) { | ||
const parts = versionToDownload.split('.') | ||
} catch (err) { | ||
// attempt to fall back to semver minor | ||
const parts = version.split('.') | ||
const baseVersion = `${parts[0]}.${parts[1]}.0` | ||
download(baseVersion, processDownload) | ||
} else { | ||
processDownload(err, zipPath) | ||
|
||
// don't recurse infinitely | ||
if (baseVersion === version) { | ||
throw err | ||
} else { | ||
await attemptDownload(baseVersion) | ||
} | ||
} | ||
}) | ||
} | ||
|
||
attemptDownload(versionToDownload) |
Oops, something went wrong.