Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(findpath): detect ChromeDriver path (#115)
* refactor: `findpath` functionc * fix: incorrect import * fix: import * fix: export `findpath` via package * fix: typo * feat: add ChromeDriver to `findpath` * docs: chromedriver findpath example * test: ChromeDriver DNE in normal build * fix: chromedriver assert * docs: remove `win | osx` from `hostOs` type def * docs: chromedriver var naming * refactor: code review changes
- Loading branch information
1 parent
86b52bc
commit fc3c0ef
Showing
6 changed files
with
76 additions
and
30 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { dirname } from 'node:path'; | ||
import { env, platform } from 'node:process'; | ||
import { join, resolve } from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
|
||
/** | ||
* Get the platform dependant path of the NW.js or ChromeDriver binary. | ||
* | ||
* @param {'nwjs' | 'chromedriver'} executable Path to NW.js or Chromedriver executable. | ||
* @return {string} | ||
*/ | ||
export default function findpath(executable = 'nwjs') { | ||
const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
const nwDir = resolve(__dirname, '..', 'nwjs'); | ||
/** | ||
* File path to executable. | ||
* | ||
* @type {string} | ||
*/ | ||
let binPath = ''; | ||
|
||
/** | ||
* Host operating system | ||
* | ||
* @type {NodeJS.Platform} | ||
*/ | ||
let hostOs = env.npm_config_nwjs_platform || env.NWJS_PLATFORM || platform; | ||
|
||
/** | ||
* Get the platform dependant path of the NW.js binary. | ||
*/ | ||
function findNwjs() { | ||
if (hostOs === 'darwin') { | ||
binPath = join(nwDir, 'nwjs.app', 'Contents', 'MacOS', 'nwjs'); | ||
} else if (hostOs === 'win32') { | ||
binPath = join(nwDir, 'nw.exe'); | ||
} else { | ||
binPath = join(nwDir, 'nw'); | ||
} | ||
} | ||
|
||
/** | ||
* Get the platform dependant path of the ChromeDriver binary. | ||
*/ | ||
function findChromeDriver() { | ||
binPath = resolve(nwDir, `chromedriver${platform === "win32" ? ".exe" : ""}`); | ||
} | ||
|
||
if (executable === 'nwjs') { | ||
findNwjs(); | ||
} else if (executable === 'chromedriver') { | ||
findChromeDriver(); | ||
} else { | ||
console.error(`[ ERROR ] Expected nwjs or chromedriver, got ${executable}.`); | ||
} | ||
|
||
return binPath; | ||
} |
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