gecko_driver_github.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const semver = require("semver");
  4. const config_source_1 = require("./config_source");
  5. class GeckoDriverGithub extends config_source_1.GithubApiConfigSource {
  6. constructor() {
  7. super('gecko', 'https://api.github.com/repos/mozilla/geckodriver/releases');
  8. }
  9. getUrl(version) {
  10. if (version === 'latest') {
  11. return this.getLatestGeckoDriverVersion();
  12. }
  13. else {
  14. return this.getSpecificGeckoDrierVersion(version);
  15. }
  16. }
  17. getVersionList() {
  18. return this.getJson().then(json => {
  19. let versions = [];
  20. for (let i = 0; i < json.length; i++) {
  21. let item = json[i];
  22. versions.push(item.tag_name);
  23. }
  24. return versions;
  25. });
  26. }
  27. getVersionsLookup() {
  28. return this.getJson().then(json => {
  29. let versionsLookup = [];
  30. for (let i = 0; i < json.length; i++) {
  31. let item = json[i];
  32. let index = i.toString();
  33. versionsLookup.push({ version: item.tag_name, index: index });
  34. }
  35. return versionsLookup;
  36. });
  37. }
  38. getLatestGeckoDriverVersion() {
  39. return this.getJson().then(json => {
  40. return this.getVersionsLookup().then(versionsLookup => {
  41. let latest = '';
  42. for (let item of versionsLookup) {
  43. let version = item.version.replace('v', '');
  44. let assetsArray = json[item.index].assets;
  45. // check to make sure the version found has the OS
  46. for (let asset of assetsArray) {
  47. if (asset.name.includes(this.oshelper())) {
  48. if (latest === '') {
  49. latest = version;
  50. }
  51. else if (semver.lt(latest, version)) {
  52. latest = version;
  53. }
  54. }
  55. }
  56. }
  57. return this.getSpecificGeckoDrierVersion('v' + latest);
  58. });
  59. });
  60. }
  61. getSpecificGeckoDrierVersion(inputVersion) {
  62. return this.getJson().then(json => {
  63. return this.getVersionsLookup().then(versionsLookup => {
  64. for (let item of versionsLookup) {
  65. // Get the asset from the matching version.
  66. if (item.version === inputVersion) {
  67. let assetsArray = json[item.index].assets;
  68. for (let asset of assetsArray) {
  69. if (asset.name.includes(this.oshelper())) {
  70. return { url: asset.browser_download_url, version: inputVersion };
  71. }
  72. }
  73. }
  74. }
  75. return null;
  76. });
  77. });
  78. }
  79. oshelper() {
  80. // Get the os type name.
  81. if (this.ostype === 'Darwin') {
  82. return 'macos';
  83. }
  84. else if (this.ostype === 'Windows_NT') {
  85. return this.osarch === 'x64' ? 'win64' : 'win32';
  86. }
  87. else {
  88. return this.osarch === 'x64' ? 'linux64' : 'linux32';
  89. }
  90. }
  91. }
  92. exports.GeckoDriverGithub = GeckoDriverGithub;
  93. //# sourceMappingURL=gecko_driver_github.js.map