binDownload.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.getBin = exports.getBinFromUrl = exports.getBinFromCustomLoc = exports.download = void 0;
  4. const builder_util_1 = require("builder-util");
  5. const versionToPromise = new Map();
  6. function download(url, output, checksum) {
  7. const args = ["download", "--url", url, "--output", output];
  8. if (checksum != null) {
  9. args.push("--sha512", checksum);
  10. }
  11. return (0, builder_util_1.executeAppBuilder)(args);
  12. }
  13. exports.download = download;
  14. function getBinFromCustomLoc(name, version, binariesLocUrl, checksum) {
  15. const dirName = `${name}-${version}`;
  16. return getBin(dirName, binariesLocUrl, checksum);
  17. }
  18. exports.getBinFromCustomLoc = getBinFromCustomLoc;
  19. function getBinFromUrl(name, version, checksum) {
  20. const dirName = `${name}-${version}`;
  21. let url;
  22. if (process.env.ELECTRON_BUILDER_BINARIES_DOWNLOAD_OVERRIDE_URL) {
  23. url = process.env.ELECTRON_BUILDER_BINARIES_DOWNLOAD_OVERRIDE_URL + "/" + dirName + ".7z";
  24. }
  25. else {
  26. const baseUrl = process.env.NPM_CONFIG_ELECTRON_BUILDER_BINARIES_MIRROR ||
  27. process.env.npm_config_electron_builder_binaries_mirror ||
  28. process.env.npm_package_config_electron_builder_binaries_mirror ||
  29. process.env.ELECTRON_BUILDER_BINARIES_MIRROR ||
  30. "https://github.com/electron-userland/electron-builder-binaries/releases/download/";
  31. const middleUrl = process.env.NPM_CONFIG_ELECTRON_BUILDER_BINARIES_CUSTOM_DIR ||
  32. process.env.npm_config_electron_builder_binaries_custom_dir ||
  33. process.env.npm_package_config_electron_builder_binaries_custom_dir ||
  34. process.env.ELECTRON_BUILDER_BINARIES_CUSTOM_DIR ||
  35. dirName;
  36. const urlSuffix = dirName + ".7z";
  37. url = `${baseUrl}${middleUrl}/${urlSuffix}`;
  38. }
  39. return getBin(dirName, url, checksum);
  40. }
  41. exports.getBinFromUrl = getBinFromUrl;
  42. function getBin(name, url, checksum) {
  43. // Old cache is ignored if cache environment variable changes
  44. const cacheName = `${process.env.ELECTRON_BUILDER_CACHE}${name}`;
  45. let promise = versionToPromise.get(cacheName); // if rejected, we will try to download again
  46. if (promise != null) {
  47. return promise;
  48. }
  49. promise = doGetBin(name, url, checksum);
  50. versionToPromise.set(cacheName, promise);
  51. return promise;
  52. }
  53. exports.getBin = getBin;
  54. function doGetBin(name, url, checksum) {
  55. const args = ["download-artifact", "--name", name];
  56. if (url != null) {
  57. args.push("--url", url);
  58. }
  59. if (checksum != null) {
  60. args.push("--sha512", checksum);
  61. }
  62. return (0, builder_util_1.executeAppBuilder)(args);
  63. }
  64. //# sourceMappingURL=binDownload.js.map