targetFactory.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.NoOpTarget = exports.createCommonTarget = exports.createTargets = exports.computeArchToTargetNamesMap = void 0;
  4. const builder_util_1 = require("builder-util");
  5. const core_1 = require("../core");
  6. const ArchiveTarget_1 = require("./ArchiveTarget");
  7. const archiveTargets = new Set(["zip", "7z", "tar.xz", "tar.lz", "tar.gz", "tar.bz2"]);
  8. function computeArchToTargetNamesMap(raw, platformPackager, platform) {
  9. for (const targetNames of raw.values()) {
  10. if (targetNames.length > 0) {
  11. // https://github.com/electron-userland/electron-builder/issues/1355
  12. return raw;
  13. }
  14. }
  15. const defaultArchs = raw.size === 0 ? [process.arch] : Array.from(raw.keys()).map(it => builder_util_1.Arch[it]);
  16. const result = new Map(raw);
  17. for (const target of (0, builder_util_1.asArray)(platformPackager.platformSpecificBuildOptions.target).map(it => (typeof it === "string" ? { target: it } : it))) {
  18. let name = target.target;
  19. let archs = target.arch;
  20. const suffixPos = name.lastIndexOf(":");
  21. if (suffixPos > 0) {
  22. name = target.target.substring(0, suffixPos);
  23. if (archs == null) {
  24. archs = target.target.substring(suffixPos + 1);
  25. }
  26. }
  27. for (const arch of archs == null ? defaultArchs : (0, builder_util_1.asArray)(archs)) {
  28. (0, builder_util_1.addValue)(result, (0, builder_util_1.archFromString)(arch), name);
  29. }
  30. }
  31. if (result.size === 0) {
  32. const defaultTarget = platformPackager.defaultTarget;
  33. if (raw.size === 0 && platform === core_1.Platform.LINUX && (process.platform === "darwin" || process.platform === "win32")) {
  34. result.set(builder_util_1.Arch.x64, defaultTarget);
  35. // cannot enable arm because of native dependencies - e.g. keytar doesn't provide pre-builds for arm
  36. // result.set(Arch.armv7l, ["snap"])
  37. }
  38. else {
  39. for (const arch of defaultArchs) {
  40. result.set((0, builder_util_1.archFromString)(arch), defaultTarget);
  41. }
  42. }
  43. }
  44. return result;
  45. }
  46. exports.computeArchToTargetNamesMap = computeArchToTargetNamesMap;
  47. function createTargets(nameToTarget, rawList, outDir, packager) {
  48. const result = [];
  49. const mapper = (name, factory) => {
  50. let target = nameToTarget.get(name);
  51. if (target == null) {
  52. target = factory(outDir);
  53. nameToTarget.set(name, target);
  54. }
  55. result.push(target);
  56. };
  57. const targets = normalizeTargets(rawList, packager.defaultTarget);
  58. packager.createTargets(targets, mapper);
  59. return result;
  60. }
  61. exports.createTargets = createTargets;
  62. function normalizeTargets(targets, defaultTarget) {
  63. const list = [];
  64. for (const t of targets) {
  65. const name = t.toLowerCase().trim();
  66. if (name === core_1.DEFAULT_TARGET) {
  67. list.push(...defaultTarget);
  68. }
  69. else {
  70. list.push(name);
  71. }
  72. }
  73. return list;
  74. }
  75. function createCommonTarget(target, outDir, packager) {
  76. if (archiveTargets.has(target)) {
  77. return new ArchiveTarget_1.ArchiveTarget(target, outDir, packager);
  78. }
  79. else if (target === core_1.DIR_TARGET) {
  80. return new NoOpTarget(core_1.DIR_TARGET);
  81. }
  82. else {
  83. throw new Error(`Unknown target: ${target}`);
  84. }
  85. }
  86. exports.createCommonTarget = createCommonTarget;
  87. class NoOpTarget extends core_1.Target {
  88. constructor(name) {
  89. super(name);
  90. this.options = null;
  91. }
  92. get outDir() {
  93. throw new Error("NoOpTarget");
  94. }
  95. // eslint-disable-next-line
  96. async build(appOutDir, arch) {
  97. // no build
  98. }
  99. }
  100. exports.NoOpTarget = NoOpTarget;
  101. //# sourceMappingURL=targetFactory.js.map