standalone_xml.js 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const semver = require("semver");
  4. const config_1 = require("../config");
  5. const config_source_1 = require("./config_source");
  6. class StandaloneXml extends config_source_1.XmlConfigSource {
  7. constructor() {
  8. super('standalone', config_1.Config.cdnUrls()['selenium']);
  9. }
  10. getUrl(version) {
  11. if (version === 'latest') {
  12. return this.getLatestStandaloneVersion();
  13. }
  14. else {
  15. return this.getSpecificStandaloneVersion(version);
  16. }
  17. }
  18. getVersionList() {
  19. return this.getXml().then(xml => {
  20. let versionPaths = [];
  21. for (let content of xml.ListBucketResult.Contents) {
  22. let contentKey = content.Key[0];
  23. // Filter the selenium-server-standalone.
  24. if (contentKey.includes('selenium-server-standalone')) {
  25. versionPaths.push(contentKey);
  26. }
  27. }
  28. return versionPaths;
  29. });
  30. }
  31. getLatestStandaloneVersion() {
  32. return this.getVersionList().then(list => {
  33. let standaloneVersion = null;
  34. let latest = '';
  35. let latestVersion = '';
  36. // Use jar files that are not beta and not alpha versions.
  37. const jarList = list.filter((i) => {
  38. return i.endsWith('.jar') && !i.includes('beta') && !i.includes('alpha');
  39. });
  40. for (let item of jarList) {
  41. // Get a semantic version.
  42. let version = item.split('selenium-server-standalone-')[1].replace('.jar', '');
  43. if (standaloneVersion == null) {
  44. // First time: use the version found.
  45. standaloneVersion = version;
  46. latest = item;
  47. latestVersion = version;
  48. }
  49. else if (semver.gt(version, standaloneVersion)) {
  50. // Get the latest.
  51. standaloneVersion = version;
  52. latest = item;
  53. latestVersion = version;
  54. }
  55. }
  56. return { url: config_1.Config.cdnUrls().selenium + latest, version: latestVersion };
  57. });
  58. }
  59. getSpecificStandaloneVersion(inputVersion) {
  60. return this.getVersionList().then(list => {
  61. let itemFound = '';
  62. let standaloneVersion = null;
  63. for (let item of list) {
  64. // Get a semantic version.
  65. let version = item.split('selenium-server-standalone-')[1].replace('.jar', '');
  66. // Check to see if the specified version matches.
  67. let firstPath = item.split('/')[0];
  68. if (version === inputVersion) {
  69. // Check if the beta exists that we have the right version
  70. // Example: We will see that beta3 appears in the file and path
  71. // 3.0-beta3/selenium-server-standalone-3.0.0-beta3.jar
  72. // where this should not work:
  73. // 3.0-beta2/selenium-server-standalone-3.0.0-beta3.jar
  74. if (inputVersion.includes('beta')) {
  75. let betaInputVersion = inputVersion.replace('.jar', '').split('beta')[1];
  76. if (item.split('/')[0].includes('beta' + betaInputVersion)) {
  77. return { url: config_1.Config.cdnUrls().selenium + item, version: version };
  78. }
  79. }
  80. else {
  81. return { url: config_1.Config.cdnUrls().selenium + item, version: version };
  82. }
  83. }
  84. }
  85. });
  86. }
  87. }
  88. exports.StandaloneXml = StandaloneXml;
  89. //# sourceMappingURL=standalone_xml.js.map