status.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const fs = require("fs");
  4. const minimist = require("minimist");
  5. const path = require("path");
  6. const semver = require("semver");
  7. const binaries_1 = require("../binaries");
  8. const chrome_xml_1 = require("../binaries/chrome_xml");
  9. const cli_1 = require("../cli");
  10. const config_1 = require("../config");
  11. const files_1 = require("../files");
  12. const Opt = require("./");
  13. const opts_1 = require("./opts");
  14. let logger = new cli_1.Logger('status');
  15. let prog = new cli_1.Program()
  16. .command('status', 'list the current available drivers')
  17. .addOption(opts_1.Opts[Opt.OUT_DIR])
  18. .action(status);
  19. exports.program = prog;
  20. // stand alone runner
  21. let argv = minimist(process.argv.slice(2), prog.getMinimistOptions());
  22. if (argv._[0] === 'status-run') {
  23. prog.run(JSON.parse(JSON.stringify(argv)));
  24. }
  25. else if (argv._[0] === 'status-help') {
  26. prog.printHelp();
  27. }
  28. /**
  29. * Parses the options and logs the status of the binaries downloaded.
  30. * @param options
  31. */
  32. function status(options) {
  33. let binaries = files_1.FileManager.setupBinaries();
  34. let outputDir = config_1.Config.getSeleniumDir();
  35. if (options[Opt.OUT_DIR].value) {
  36. if (path.isAbsolute(options[Opt.OUT_DIR].getString())) {
  37. outputDir = options[Opt.OUT_DIR].getString();
  38. }
  39. else {
  40. outputDir = path.resolve(config_1.Config.getBaseDir(), options[Opt.OUT_DIR].getString());
  41. }
  42. }
  43. try {
  44. // check if folder exists
  45. fs.statSync(outputDir).isDirectory();
  46. }
  47. catch (e) {
  48. // if the folder does not exist, quit early.
  49. logger.warn('the out_dir path ' + outputDir + ' does not exist');
  50. return;
  51. }
  52. // Try to get the update-config.json. This will be used for showing the last binary downloaded.
  53. let updateConfig = {};
  54. try {
  55. updateConfig =
  56. JSON.parse(fs.readFileSync(path.resolve(outputDir, 'update-config.json')).toString()) || {};
  57. }
  58. catch (err) {
  59. updateConfig = {};
  60. }
  61. let downloadedBinaries = files_1.FileManager.downloadedBinaries(outputDir);
  62. // Log which binaries have been downloaded.
  63. for (let bin in downloadedBinaries) {
  64. let downloaded = downloadedBinaries[bin];
  65. let log = downloaded.name + ' ';
  66. log += downloaded.versions.length == 1 ? 'version available: ' : 'versions available: ';
  67. // Get the "last" downloaded binary from the updateConfig.
  68. let last = null;
  69. if (downloaded.binary instanceof binaries_1.Appium && updateConfig[binaries_1.Appium.id]) {
  70. last = updateConfig[binaries_1.Appium.id]['last'];
  71. }
  72. else if (downloaded.binary instanceof binaries_1.AndroidSDK && updateConfig[binaries_1.AndroidSDK.id]) {
  73. last = updateConfig[binaries_1.AndroidSDK.id]['last'];
  74. }
  75. else if (downloaded.binary instanceof binaries_1.ChromeDriver && updateConfig[binaries_1.ChromeDriver.id]) {
  76. last = updateConfig[binaries_1.ChromeDriver.id]['last'];
  77. }
  78. else if (downloaded.binary instanceof binaries_1.GeckoDriver && updateConfig[binaries_1.GeckoDriver.id]) {
  79. last = updateConfig[binaries_1.GeckoDriver.id]['last'];
  80. }
  81. else if (downloaded.binary instanceof binaries_1.IEDriver && updateConfig[binaries_1.IEDriver.id]) {
  82. last = updateConfig[binaries_1.IEDriver.id]['last'];
  83. }
  84. else if (downloaded.binary instanceof binaries_1.Standalone && updateConfig[binaries_1.Standalone.id]) {
  85. last = updateConfig[binaries_1.Standalone.id]['last'];
  86. }
  87. // Sort the versions then log them:
  88. // - last: the last binary downloaded by webdriver-manager per the update-config.json
  89. downloaded.versions = downloaded.versions.sort((a, b) => {
  90. if (!semver.valid(a)) {
  91. a = chrome_xml_1.getValidSemver(a);
  92. b = chrome_xml_1.getValidSemver(b);
  93. }
  94. if (semver.gt(a, b)) {
  95. return 1;
  96. }
  97. else {
  98. return 0;
  99. }
  100. });
  101. for (let ver in downloaded.versions) {
  102. let version = downloaded.versions[ver];
  103. log += version;
  104. if (last && last.indexOf(version) >= 0) {
  105. log += ' [last]';
  106. }
  107. if (+ver != downloaded.versions.length - 1) {
  108. log += ', ';
  109. }
  110. }
  111. logger.info(log);
  112. }
  113. // for binaries that are available for the operating system, show them here
  114. for (let bin in binaries) {
  115. if (downloadedBinaries[bin] == null) {
  116. logger.info(binaries[bin].name + ' is not present');
  117. }
  118. }
  119. }
  120. //# sourceMappingURL=status.js.map