MsiWrappedTarget.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const builder_util_1 = require("builder-util");
  4. const builder_util_runtime_1 = require("builder-util-runtime");
  5. const path = require("path");
  6. const MsiTarget_1 = require("./MsiTarget");
  7. const ELECTRON_MSI_WRAPPED_NS_UUID = builder_util_runtime_1.UUID.parse("467f7bb2-a83c-442f-b776-394d316e8e53");
  8. class MsiWrappedTarget extends MsiTarget_1.default {
  9. constructor(packager, outDir) {
  10. // must be synchronous so it can run after nsis
  11. super(packager, outDir, "msiWrapped", false);
  12. this.outDir = outDir;
  13. this.options = (0, builder_util_1.deepAssign)(this.packager.platformSpecificBuildOptions, this.packager.config.msiWrapped);
  14. /** @private */
  15. this.archs = new Map();
  16. }
  17. get productId() {
  18. // this id is only required to build the installer
  19. // however it serves no purpose as this msi is just
  20. // a wrapper for an exe
  21. return builder_util_runtime_1.UUID.v5(this.packager.appInfo.id, ELECTRON_MSI_WRAPPED_NS_UUID).toUpperCase();
  22. }
  23. validatePrerequisites() {
  24. const config = this.packager.config;
  25. // this target requires nsis to be configured and executed
  26. // as this build re-bundles the nsis executable and wraps it in an msi
  27. if (!config.win || !config.win.target || !Array.isArray(config.win.target)) {
  28. throw new Error("No windows target found!");
  29. }
  30. const target = config.win.target;
  31. const nsisTarget = "nsis";
  32. if (!target
  33. .map((t) => {
  34. const result = typeof t === "string" ? t : t.target;
  35. return result.toLowerCase().trim();
  36. })
  37. .some(t => t === nsisTarget)) {
  38. throw new Error("No nsis target found! Please specify an nsis target");
  39. }
  40. }
  41. build(appOutDir, arch) {
  42. this.archs.set(arch, appOutDir);
  43. return Promise.resolve();
  44. }
  45. finishBuild() {
  46. // this target invokes `build` in `finishBuild` to guarantee
  47. // that the dependent target has already been built
  48. // this also affords us re-usability
  49. const [arch, appOutDir] = this.archs.entries().next().value;
  50. this.validatePrerequisites();
  51. return super.build(appOutDir, arch);
  52. }
  53. get installerFilenamePattern() {
  54. // big assumption is made here for the moment that the pattern didn't change
  55. // tslint:disable:no-invalid-template-strings
  56. return "${productName} Setup ${version}.${ext}";
  57. }
  58. getExeSourcePath(arch) {
  59. const packager = this.packager;
  60. // in this case, we want .exe, this way we can wrap the existing package if it exists
  61. const artifactName = packager.expandArtifactNamePattern(this.options, "exe", arch, this.installerFilenamePattern, false, this.packager.platformSpecificBuildOptions.defaultArch);
  62. const artifactPath = path.join(this.outDir, artifactName);
  63. return artifactPath;
  64. }
  65. async writeManifest(_appOutDir, arch, commonOptions) {
  66. const exeSourcePath = this.getExeSourcePath(arch);
  67. const options = this.options;
  68. return (await this.projectTemplate.value)({
  69. ...(await this.getBaseOptions(commonOptions)),
  70. exeSourcePath: exeSourcePath,
  71. productId: this.productId,
  72. impersonate: options.impersonate === true ? "yes" : "no",
  73. wrappedInstallerArgs: options.wrappedInstallerArgs,
  74. });
  75. }
  76. }
  77. exports.default = MsiWrappedTarget;
  78. //# sourceMappingURL=MsiWrappedTarget.js.map