binary.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const fs = require("fs");
  4. const config_1 = require("../config");
  5. /**
  6. * operating system enum
  7. */
  8. var OS;
  9. (function (OS) {
  10. OS[OS["Windows_NT"] = 0] = "Windows_NT";
  11. OS[OS["Linux"] = 1] = "Linux";
  12. OS[OS["Darwin"] = 2] = "Darwin";
  13. })(OS = exports.OS || (exports.OS = {}));
  14. class Binary {
  15. constructor(opt_alternativeCdn) {
  16. this.ostype = config_1.Config.osType();
  17. this.osarch = config_1.Config.osArch();
  18. this.cdn = opt_alternativeCdn;
  19. }
  20. executableSuffix() {
  21. if (this.ostype == 'Windows_NT') {
  22. return '.exe';
  23. }
  24. else {
  25. return '';
  26. }
  27. }
  28. version() {
  29. return this.versionCustom;
  30. }
  31. filename() {
  32. return this.prefix() + this.version() + this.suffix();
  33. }
  34. /**
  35. * @param ostype The operating system.
  36. * @returns The file name for the executable.
  37. */
  38. executableFilename() {
  39. return this.prefix() + this.version() + this.executableSuffix();
  40. }
  41. /**
  42. * Gets the url to download the file set by the version. This will use the XML if available.
  43. * If not, it will download from an existing url.
  44. *
  45. * @param {string} version The version we are looking for. This could also be 'latest'.
  46. */
  47. getUrl(version) {
  48. if (this.alternativeDownloadUrl != null) {
  49. return Promise.resolve({ url: '', version: '' });
  50. }
  51. else {
  52. return this.getVersionList().then(() => {
  53. version = version || config_1.Config.binaryVersions()[this.id()];
  54. return this.configSource.getUrl(version).then(binaryUrl => {
  55. this.versionCustom = binaryUrl.version;
  56. return { url: binaryUrl.url, version: binaryUrl.version };
  57. });
  58. });
  59. }
  60. }
  61. /**
  62. * Delete an instance of this binary from the file system
  63. */
  64. remove(filename) {
  65. fs.unlinkSync(filename);
  66. }
  67. /**
  68. * @param ostype The operating system.
  69. * @returns The file name for the file inside the downloaded zip file
  70. */
  71. zipContentName() {
  72. return this.name + this.executableSuffix();
  73. }
  74. }
  75. exports.Binary = Binary;
  76. //# sourceMappingURL=binary.js.map