UNPKG

5.31 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.RemoteBuilder = void 0;
7
8function _bluebirdLst() {
9 const data = _interopRequireWildcard(require("bluebird-lst"));
10
11 _bluebirdLst = function () {
12 return data;
13 };
14
15 return data;
16}
17
18function _builderUtil() {
19 const data = require("builder-util");
20
21 _builderUtil = function () {
22 return data;
23 };
24
25 return data;
26}
27
28var path = _interopRequireWildcard(require("path"));
29
30function _core() {
31 const data = require("../core");
32
33 _core = function () {
34 return data;
35 };
36
37 return data;
38}
39
40function _ProjectInfoManager() {
41 const data = require("./ProjectInfoManager");
42
43 _ProjectInfoManager = function () {
44 return data;
45 };
46
47 return data;
48}
49
50function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
51
52class RemoteBuilder {
53 constructor(packager) {
54 this.packager = packager;
55 this.toBuild = new Map();
56 this.buildStarted = false;
57 }
58
59 scheduleBuild(target, arch, unpackedDirectory) {
60 if (!(0, _builderUtil().isEnvTrue)(process.env._REMOTE_BUILD) && this.packager.config.remoteBuild === false) {
61 throw new Error("Target is not supported on your OS and using of Electron Build Service is disabled (\"remoteBuild\" option)");
62 }
63
64 let list = this.toBuild.get(arch);
65
66 if (list == null) {
67 list = [];
68 this.toBuild.set(arch, list);
69 }
70
71 list.push({
72 name: target.name,
73 arch: _builderUtil().Arch[arch],
74 unpackedDirectory,
75 outDir: target.outDir
76 });
77 }
78
79 build() {
80 if (this.buildStarted) {
81 return Promise.resolve();
82 }
83
84 this.buildStarted = true;
85 return _bluebirdLst().default.mapSeries(Array.from(this.toBuild.keys()), arch => {
86 return this._build(this.toBuild.get(arch), this.packager);
87 });
88 } // noinspection JSMethodCanBeStatic
89
90
91 _build(targets, packager) {
92 var _this = this;
93
94 return (0, _bluebirdLst().coroutine)(function* () {
95 if (_builderUtil().log.isDebugEnabled) {
96 _builderUtil().log.debug({
97 remoteTargets: JSON.stringify(targets, null, 2)
98 }, "remote building");
99 }
100
101 const projectInfoManager = new (_ProjectInfoManager().ProjectInfoManager)(packager.info); // let result: RemoteBuilderResponse | null = null
102
103 const req = Buffer.from(JSON.stringify({
104 targets: targets.map(it => {
105 return {
106 name: it.name,
107 arch: it.arch,
108 unpackedDirName: path.basename(it.unpackedDirectory)
109 };
110 }),
111 platform: packager.platform.buildConfigurationKey
112 })).toString("base64");
113 const outDir = targets[0].outDir;
114 const args = ["remote-build", "--request", req, "--output", outDir];
115 args.push("--file", targets[0].unpackedDirectory);
116 args.push("--file", (yield projectInfoManager.infoFile.value));
117 const buildResourcesDir = packager.buildResourcesDir;
118
119 if (buildResourcesDir === packager.projectDir) {
120 throw new (_builderUtil().InvalidConfigurationError)(`Build resources dir equals to project dir and so, not sent to remote build agent. It will lead to incorrect results.\nPlease set "directories.buildResources" to separate dir or leave default ("build" directory in the project root)`);
121 }
122
123 args.push("--file", buildResourcesDir);
124 const result = yield (0, _builderUtil().executeAppBuilderAsJson)(args);
125
126 if (result.error != null) {
127 throw new (_builderUtil().InvalidConfigurationError)(`Remote builder error (if you think that it is not your application misconfiguration issue, please file issue to https://github.com/electron-userland/electron-builder/issues):\n\n${result.error}`, "REMOTE_BUILDER_ERROR");
128 } else if (result.files != null) {
129 for (const artifact of result.files) {
130 const localFile = path.join(outDir, artifact.file);
131
132 const artifactCreatedEvent = _this.artifactInfoToArtifactCreatedEvent(artifact, localFile, outDir); // PublishManager uses outDir and options, real (the same as for local build) values must be used
133
134
135 _this.packager.info.dispatchArtifactCreated(artifactCreatedEvent);
136 }
137 }
138 })();
139 }
140
141 artifactInfoToArtifactCreatedEvent(artifact, localFile, outDir) {
142 const target = artifact.target; // noinspection SpellCheckingInspection
143
144 return Object.assign({}, artifact, {
145 file: localFile,
146 target: target == null ? null : new FakeTarget(target, outDir, this.packager.config[target]),
147 packager: this.packager
148 });
149 }
150
151}
152
153exports.RemoteBuilder = RemoteBuilder;
154
155class FakeTarget extends _core().Target {
156 constructor(name, outDir, options) {
157 super(name);
158 this.outDir = outDir;
159 this.options = options;
160 }
161
162 build(appOutDir, arch) {// no build
163
164 return (0, _bluebirdLst().coroutine)(function* () {})();
165 }
166
167}
168//# sourceMappingURL=RemoteBuilder.js.map
\No newline at end of file