index.js 5.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.build = exports.checkBuildRequestOptions = exports.buildForge = exports.PlatformPackager = exports.PublishManager = exports.CancellationToken = exports.AppInfo = exports.archFromString = exports.Arch = exports.getArchSuffix = exports.DEFAULT_TARGET = exports.DIR_TARGET = exports.Target = exports.Platform = exports.Packager = void 0;
  4. const promise_1 = require("builder-util/out/promise");
  5. const builder_util_1 = require("builder-util");
  6. const builder_util_runtime_1 = require("builder-util-runtime");
  7. const packager_1 = require("./packager");
  8. const platformPackager_1 = require("./platformPackager");
  9. const PublishManager_1 = require("./publish/PublishManager");
  10. var packager_2 = require("./packager");
  11. Object.defineProperty(exports, "Packager", { enumerable: true, get: function () { return packager_2.Packager; } });
  12. var core_1 = require("./core");
  13. Object.defineProperty(exports, "Platform", { enumerable: true, get: function () { return core_1.Platform; } });
  14. Object.defineProperty(exports, "Target", { enumerable: true, get: function () { return core_1.Target; } });
  15. Object.defineProperty(exports, "DIR_TARGET", { enumerable: true, get: function () { return core_1.DIR_TARGET; } });
  16. Object.defineProperty(exports, "DEFAULT_TARGET", { enumerable: true, get: function () { return core_1.DEFAULT_TARGET; } });
  17. var builder_util_2 = require("builder-util");
  18. Object.defineProperty(exports, "getArchSuffix", { enumerable: true, get: function () { return builder_util_2.getArchSuffix; } });
  19. Object.defineProperty(exports, "Arch", { enumerable: true, get: function () { return builder_util_2.Arch; } });
  20. Object.defineProperty(exports, "archFromString", { enumerable: true, get: function () { return builder_util_2.archFromString; } });
  21. var appInfo_1 = require("./appInfo");
  22. Object.defineProperty(exports, "AppInfo", { enumerable: true, get: function () { return appInfo_1.AppInfo; } });
  23. var builder_util_runtime_2 = require("builder-util-runtime");
  24. Object.defineProperty(exports, "CancellationToken", { enumerable: true, get: function () { return builder_util_runtime_2.CancellationToken; } });
  25. var PublishManager_2 = require("./publish/PublishManager");
  26. Object.defineProperty(exports, "PublishManager", { enumerable: true, get: function () { return PublishManager_2.PublishManager; } });
  27. var platformPackager_2 = require("./platformPackager");
  28. Object.defineProperty(exports, "PlatformPackager", { enumerable: true, get: function () { return platformPackager_2.PlatformPackager; } });
  29. var forge_maker_1 = require("./forge-maker");
  30. Object.defineProperty(exports, "buildForge", { enumerable: true, get: function () { return forge_maker_1.buildForge; } });
  31. const expectedOptions = new Set(["publish", "targets", "mac", "win", "linux", "projectDir", "platformPackagerFactory", "config", "effectiveOptionComputed", "prepackaged"]);
  32. function checkBuildRequestOptions(options) {
  33. for (const optionName of Object.keys(options)) {
  34. if (!expectedOptions.has(optionName) && options[optionName] !== undefined) {
  35. throw new builder_util_1.InvalidConfigurationError(`Unknown option "${optionName}"`);
  36. }
  37. }
  38. }
  39. exports.checkBuildRequestOptions = checkBuildRequestOptions;
  40. function build(options, packager = new packager_1.Packager(options)) {
  41. checkBuildRequestOptions(options);
  42. const publishManager = new PublishManager_1.PublishManager(packager, options);
  43. const sigIntHandler = () => {
  44. builder_util_1.log.warn("cancelled by SIGINT");
  45. packager.cancellationToken.cancel();
  46. publishManager.cancelTasks();
  47. };
  48. process.once("SIGINT", sigIntHandler);
  49. const promise = packager.build().then(async (buildResult) => {
  50. const afterAllArtifactBuild = (0, platformPackager_1.resolveFunction)(buildResult.configuration.afterAllArtifactBuild, "afterAllArtifactBuild");
  51. if (afterAllArtifactBuild != null) {
  52. const newArtifacts = (0, builder_util_runtime_1.asArray)(await Promise.resolve(afterAllArtifactBuild(buildResult)));
  53. if (newArtifacts.length === 0 || !publishManager.isPublish) {
  54. return buildResult.artifactPaths;
  55. }
  56. const publishConfigurations = await publishManager.getGlobalPublishConfigurations();
  57. if (publishConfigurations == null || publishConfigurations.length === 0) {
  58. return buildResult.artifactPaths;
  59. }
  60. for (const newArtifact of newArtifacts) {
  61. buildResult.artifactPaths.push(newArtifact);
  62. for (const publishConfiguration of publishConfigurations) {
  63. publishManager.scheduleUpload(publishConfiguration, {
  64. file: newArtifact,
  65. arch: null,
  66. }, packager.appInfo);
  67. }
  68. }
  69. }
  70. return buildResult.artifactPaths;
  71. });
  72. return (0, promise_1.executeFinally)(promise, isErrorOccurred => {
  73. let promise;
  74. if (isErrorOccurred) {
  75. publishManager.cancelTasks();
  76. promise = Promise.resolve(null);
  77. }
  78. else {
  79. promise = publishManager.awaitTasks();
  80. }
  81. return promise.then(() => process.removeListener("SIGINT", sigIntHandler));
  82. });
  83. }
  84. exports.build = build;
  85. //# sourceMappingURL=index.js.map