Skip to content

Commit

Permalink
feat: Make logging optional, export main
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyparrish committed Jan 28, 2022
1 parent 5f4cc57 commit 1d7bb17
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ const INSTALLER_CLASSES = [
* Install drivers to match all detected browsers.
*
* @param {string=} outputDirectory Defaults to ./
* @param {boolean=} logging
* @return {!Promise}
*/
async function main(outputDirectory) {
outputDirectory = outputDirectory || '.';

console.log(`Installing binaries to ${outputDirectory}`);
async function main(outputDirectory='.', logging=true) {
if (logging) {
console.log(`Installing binaries to ${outputDirectory}`);
}

for (const InstallerClass of INSTALLER_CLASSES) {
const installer = new InstallerClass();
Expand All @@ -35,22 +36,28 @@ async function main(outputDirectory) {
const browserVersion = await installer.getInstalledBrowserVersion();

if (browserVersion == null) {
console.log(`${browserName} not found.`);
if (logging) {
console.log(`${browserName} not found.`);
}
} else {
const installedDriverVersion =
await installer.getInstalledDriverVersion(outputDirectory);
const bestDriverVersion =
await installer.getBestDriverVersion(browserVersion);

if (installedDriverVersion == bestDriverVersion) {
console.log(
`Version ${installedDriverVersion} of ${driverName}` +
` already installed for ${browserName} version ${browserVersion}`);
if (logging) {
console.log(
`Version ${installedDriverVersion} of ${driverName} already` +
` installed for ${browserName} version ${browserVersion}`);
}
} else {
await installer.install(bestDriverVersion, outputDirectory);
console.log(
`Installed version ${bestDriverVersion} of ${driverName}` +
` for ${browserName} version ${browserVersion}`);
if (logging) {
console.log(
`Installed version ${bestDriverVersion} of ${driverName}` +
` for ${browserName} version ${browserVersion}`);
}
}
}
}
Expand All @@ -67,4 +74,6 @@ if (require.main == module) {
}

main(args[0]);
} else {
module.exports = {installWebDrivers: main};
}

0 comments on commit 1d7bb17

Please sign in to comment.