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 pathstatus.ts
More file actions
119 lines (107 loc) · 4.05 KB
/
status.ts
File metadata and controls
119 lines (107 loc) · 4.05 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import * as fs from 'fs';
import * as minimist from 'minimist';
import * as path from 'path';
import * as semver from 'semver';
import {AndroidSDK, Appium, ChromeDriver, GeckoDriver, IEDriver, Standalone} from '../binaries';
import {getValidSemver} from '../binaries/chrome_xml';
import {Logger, Options, Program} from '../cli';
import {Config} from '../config';
import {FileManager} from '../files';
import * as Opt from './';
import {Opts} from './opts';
let logger = new Logger('status');
let prog = new Program()
.command('status', 'list the current available drivers')
.addOption(Opts[Opt.OUT_DIR])
.action(status);
export var program = prog;
// stand alone runner
let argv = minimist(process.argv.slice(2), prog.getMinimistOptions());
if (argv._[0] === 'status-run') {
prog.run(JSON.parse(JSON.stringify(argv)));
} else if (argv._[0] === 'status-help') {
prog.printHelp();
}
/**
* Parses the options and logs the status of the binaries downloaded.
* @param options
*/
function status(options: Options) {
let binaries = FileManager.setupBinaries();
let outputDir = Config.getSeleniumDir();
if (options[Opt.OUT_DIR].value) {
if (path.isAbsolute(options[Opt.OUT_DIR].getString())) {
outputDir = options[Opt.OUT_DIR].getString();
} else {
outputDir = path.resolve(Config.getBaseDir(), options[Opt.OUT_DIR].getString());
}
}
try {
// check if folder exists
fs.statSync(outputDir).isDirectory();
} catch (e) {
// if the folder does not exist, quit early.
logger.warn('the out_dir path ' + outputDir + ' does not exist');
return;
}
// Try to get the update-config.json. This will be used for showing the last binary downloaded.
let updateConfig: any = {};
try {
updateConfig =
JSON.parse(fs.readFileSync(path.resolve(outputDir, 'update-config.json')).toString()) || {};
} catch (err) {
updateConfig = {};
}
let downloadedBinaries = FileManager.downloadedBinaries(outputDir);
// Log which binaries have been downloaded.
for (let bin in downloadedBinaries) {
let downloaded = downloadedBinaries[bin];
let log = downloaded.name + ' ';
log += downloaded.versions.length == 1 ? 'version available: ' : 'versions available: ';
// Get the "last" downloaded binary from the updateConfig.
let last: string = null;
if (downloaded.binary instanceof Appium && updateConfig[Appium.id]) {
last = updateConfig[Appium.id]['last'];
} else if (downloaded.binary instanceof AndroidSDK && updateConfig[AndroidSDK.id]) {
last = updateConfig[AndroidSDK.id]['last'];
} else if (downloaded.binary instanceof ChromeDriver && updateConfig[ChromeDriver.id]) {
last = updateConfig[ChromeDriver.id]['last'];
} else if (downloaded.binary instanceof GeckoDriver && updateConfig[GeckoDriver.id]) {
last = updateConfig[GeckoDriver.id]['last'];
} else if (downloaded.binary instanceof IEDriver && updateConfig[IEDriver.id]) {
last = updateConfig[IEDriver.id]['last'];
} else if (downloaded.binary instanceof Standalone && updateConfig[Standalone.id]) {
last = updateConfig[Standalone.id]['last'];
}
// Sort the versions then log them:
// - last: the last binary downloaded by webdriver-manager per the update-config.json
downloaded.versions = downloaded.versions.sort((a: string, b: string): number => {
if (!semver.valid(a)) {
a = getValidSemver(a);
b = getValidSemver(b);
}
if (semver.gt(a, b)) {
return 1;
} else {
return -1;
}
});
for (let ver in downloaded.versions) {
let version = downloaded.versions[ver];
log += version;
if (last && last.indexOf(version) >= 0) {
log += ' [last]'
}
if (+ver != downloaded.versions.length - 1) {
log += ', ';
}
}
logger.info(log);
}
// for binaries that are available for the operating system, show them here
for (let bin in binaries) {
if (downloadedBinaries[bin] == null) {
logger.info(binaries[bin].name + ' is not present');
}
}
}