This repository was archived by the owner on Apr 17, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 113
Expand file tree
/
Copy pathgecko_driver_github.ts
More file actions
97 lines (87 loc) · 3 KB
/
gecko_driver_github.ts
File metadata and controls
97 lines (87 loc) · 3 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import * as semver from 'semver';
import {Config} from '../config';
import {BinaryUrl} from './binary';
import {GithubApiConfigSource} from './config_source';
export class GeckoDriverGithub extends GithubApiConfigSource {
constructor() {
super('gecko', 'https://api.github.com/repos/mozilla/geckodriver/releases');
}
getUrl(version: string): Promise<BinaryUrl> {
if (version === 'latest') {
return this.getLatestGeckoDriverVersion();
} else {
return this.getSpecificGeckoDrierVersion(version);
}
}
getVersionList(): Promise<string[]> {
return this.getJson().then(json => {
let versions: string[] = [];
for (let i = 0; i < json.length; i++) {
let item = json[i];
versions.push(item.tag_name);
}
return versions;
});
}
getVersionsLookup(): Promise<Array<{version: string, index: string}>> {
return this.getJson().then(json => {
let versionsLookup: Array<{version: string, index: string}> = [];
for (let i = 0; i < json.length; i++) {
let item = json[i];
let index = i.toString();
versionsLookup.push({version: item.tag_name, index: index});
}
return versionsLookup;
});
}
private getLatestGeckoDriverVersion(): Promise<BinaryUrl> {
return this.getJson().then(json => {
return this.getVersionsLookup().then(versionsLookup => {
let latest = '';
for (let item of versionsLookup) {
let version = item.version.replace('v', '');
let assetsArray = json[item.index].assets;
// check to make sure the version found has the OS
for (let asset of assetsArray) {
if ((asset.name as string).includes(this.oshelper())) {
if (latest === '') {
latest = version;
} else if (semver.lt(latest, version)) {
latest = version;
}
}
}
}
return this.getSpecificGeckoDrierVersion('v' + latest);
});
});
}
private getSpecificGeckoDrierVersion(inputVersion: string): Promise<BinaryUrl> {
return this.getJson().then(json => {
return this.getVersionsLookup().then(versionsLookup => {
for (let item of versionsLookup) {
// Get the asset from the matching version.
if (item.version === inputVersion) {
let assetsArray = json[item.index].assets;
for (let asset of assetsArray) {
if ((asset.name as string).includes(this.oshelper() + '.')) {
return {url: asset.browser_download_url, version: inputVersion};
}
}
}
}
return null;
});
});
}
private oshelper(): string {
// Get the os type name.
if (this.ostype === 'Darwin') {
return this.osarch === 'x64' ? 'macos' : 'macos-aarch64';
} else if (this.ostype === 'Windows_NT') {
return this.osarch === 'x64' ? 'win64' : 'win32';
} else {
return this.osarch === 'x64' ? 'linux64' : 'linux32';
}
}
}