UNPKG

11.9 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.writeUpdateInfoFiles = exports.createUpdateInfoTasks = 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
28function _fsExtraP() {
29 const data = require("fs-extra-p");
30
31 _fsExtraP = function () {
32 return data;
33 };
34
35 return data;
36}
37
38function _lazyVal() {
39 const data = require("lazy-val");
40
41 _lazyVal = function () {
42 return data;
43 };
44
45 return data;
46}
47
48var path = _interopRequireWildcard(require("path"));
49
50function semver() {
51 const data = _interopRequireWildcard(require("semver"));
52
53 semver = function () {
54 return data;
55 };
56
57 return data;
58}
59
60function _core() {
61 const data = require("../core");
62
63 _core = function () {
64 return data;
65 };
66
67 return data;
68}
69
70function _PublishManager() {
71 const data = require("./PublishManager");
72
73 _PublishManager = function () {
74 return data;
75 };
76
77 return data;
78}
79
80let getReleaseInfo = (() => {
81 var _ref = (0, _bluebirdLst().coroutine)(function* (packager) {
82 const releaseInfo = Object.assign({}, packager.platformSpecificBuildOptions.releaseInfo || packager.config.releaseInfo);
83
84 if (releaseInfo.releaseNotes == null) {
85 const releaseNotesFile = yield packager.getResource(releaseInfo.releaseNotesFile, `release-notes-${packager.platform.buildConfigurationKey}.md`, `release-notes-${packager.platform.name}.md`, `release-notes-${packager.platform.nodeName}.md`, "release-notes.md");
86 const releaseNotes = releaseNotesFile == null ? null : yield (0, _fsExtraP().readFile)(releaseNotesFile, "utf-8"); // to avoid undefined in the file, check for null
87
88 if (releaseNotes != null) {
89 releaseInfo.releaseNotes = releaseNotes;
90 }
91 }
92
93 delete releaseInfo.releaseNotesFile;
94 return releaseInfo;
95 });
96
97 return function getReleaseInfo(_x) {
98 return _ref.apply(this, arguments);
99 };
100})();
101
102let createUpdateInfo = (() => {
103 var _ref3 = (0, _bluebirdLst().coroutine)(function* (version, event, releaseInfo) {
104 const customUpdateInfo = event.updateInfo;
105 const url = path.basename(event.file);
106 const sha512 = (customUpdateInfo == null ? null : customUpdateInfo.sha512) || (yield (0, _builderUtil().hashFile)(event.file));
107 const files = [{
108 url,
109 sha512
110 }];
111 const result = Object.assign({
112 version,
113 files,
114 path: url
115 /* backward compatibility, electron-updater 1.x - electron-updater 2.15.0 */
116 ,
117 sha512
118 /* backward compatibility, electron-updater 1.x - electron-updater 2.15.0 */
119
120 }, releaseInfo);
121
122 if (customUpdateInfo != null) {
123 // file info or nsis web installer packages info
124 Object.assign("sha512" in customUpdateInfo ? files[0] : result, customUpdateInfo);
125 }
126
127 return result;
128 });
129
130 return function createUpdateInfo(_x4, _x5, _x6) {
131 return _ref3.apply(this, arguments);
132 };
133})();
134
135// backward compatibility - write json file
136let writeOldMacInfo = (() => {
137 var _ref6 = (0, _bluebirdLst().coroutine)(function* (publishConfig, outDir, dir, channel, createdFiles, version, packager) {
138 const isGitHub = publishConfig.provider === "github";
139 const updateInfoFile = isGitHub && outDir === dir ? path.join(dir, "github", `${channel}-mac.json`) : path.join(dir, `${channel}-mac.json`);
140
141 if (!createdFiles.has(updateInfoFile)) {
142 createdFiles.add(updateInfoFile);
143 yield (0, _fsExtraP().outputJson)(updateInfoFile, {
144 version,
145 releaseDate: new Date().toISOString(),
146 url: (0, _PublishManager().computeDownloadUrl)(publishConfig, packager.generateName2("zip", "mac", isGitHub), packager)
147 }, {
148 spaces: 2
149 });
150 packager.info.dispatchArtifactCreated({
151 file: updateInfoFile,
152 arch: null,
153 packager,
154 target: null,
155 publishConfig
156 });
157 }
158 });
159
160 return function writeOldMacInfo(_x10, _x11, _x12, _x13, _x14, _x15, _x16) {
161 return _ref6.apply(this, arguments);
162 };
163})(); function _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; } }
164
165function isGenerateUpdatesFilesForAllChannels(packager) {
166 const value = packager.platformSpecificBuildOptions.generateUpdatesFilesForAllChannels;
167 return value == null ? packager.config.generateUpdatesFilesForAllChannels : value;
168}
169/**
170 if this is an "alpha" version, we need to generate only the "alpha" .yml file
171 if this is a "beta" version, we need to generate both the "alpha" and "beta" .yml file
172 if this is a "stable" version, we need to generate all the "alpha", "beta" and "stable" .yml file
173 */
174
175
176function computeChannelNames(packager, publishConfig) {
177 const currentChannel = publishConfig.channel || "latest"; // for GitHub should be pre-release way be used
178
179 if (currentChannel === "alpha" || publishConfig.provider === "github" || !isGenerateUpdatesFilesForAllChannels(packager)) {
180 return [currentChannel];
181 }
182
183 switch (currentChannel) {
184 case "beta":
185 return [currentChannel, "alpha"];
186
187 case "latest":
188 return [currentChannel, "alpha", "beta"];
189
190 default:
191 return [currentChannel];
192 }
193}
194
195function getUpdateInfoFileName(channel, packager, arch) {
196 const osSuffix = packager.platform === _core().Platform.WINDOWS ? "" : `-${packager.platform.buildConfigurationKey}`;
197 return `${channel}${osSuffix}${getArchPrefixForUpdateFile(arch, packager)}.yml`;
198}
199
200function getArchPrefixForUpdateFile(arch, packager) {
201 if (arch == null || arch === _builderUtil().Arch.x64 || packager.platform !== _core().Platform.LINUX) {
202 return "";
203 }
204
205 return arch === _builderUtil().Arch.armv7l ? "-arm" : `-${_builderUtil().Arch[arch]}`;
206}
207/** @internal */
208
209
210let createUpdateInfoTasks = (() => {
211 var _ref2 = (0, _bluebirdLst().coroutine)(function* (event, _publishConfigs) {
212 const packager = event.packager;
213 const publishConfigs = yield (0, _PublishManager().getPublishConfigsForUpdateInfo)(packager, _publishConfigs, event.arch);
214
215 if (publishConfigs == null || publishConfigs.length === 0) {
216 return [];
217 }
218
219 const outDir = event.target.outDir;
220 const version = packager.appInfo.version;
221 const sha2 = new (_lazyVal().Lazy)(() => (0, _builderUtil().hashFile)(event.file, "sha256", "hex"));
222
223 const isMac = packager.platform === _core().Platform.MAC;
224
225 const createdFiles = new Set();
226 const sharedInfo = yield createUpdateInfo(version, event, (yield getReleaseInfo(packager)));
227 const tasks = [];
228 const electronUpdaterCompatibility = packager.platformSpecificBuildOptions.electronUpdaterCompatibility;
229
230 for (const publishConfiguration of publishConfigs) {
231 const isBintray = publishConfiguration.provider === "bintray";
232 let dir = outDir; // Bintray uses different variant of channel file info, better to generate it to a separate dir by always
233
234 if (isBintray || publishConfigs.length > 1 && publishConfiguration !== publishConfigs[0]) {
235 dir = path.join(outDir, publishConfiguration.provider);
236 } // spaces is a new publish provider, no need to keep backward compatibility
237
238
239 let isElectronUpdater1xCompatibility = publishConfiguration.provider !== "spaces" && (electronUpdaterCompatibility == null || semver().satisfies("1.0.0", electronUpdaterCompatibility));
240 let info = sharedInfo; // noinspection JSDeprecatedSymbols
241
242 if (isElectronUpdater1xCompatibility && packager.platform === _core().Platform.WINDOWS) {
243 info = Object.assign({}, info);
244 info.sha2 = yield sha2.value;
245 }
246
247 if (event.safeArtifactName != null && publishConfiguration.provider === "github") {
248 const newFiles = info.files.slice();
249 newFiles[0].url = event.safeArtifactName;
250 info = Object.assign({}, info, {
251 files: newFiles,
252 path: event.safeArtifactName
253 });
254 }
255
256 for (const channel of computeChannelNames(packager, publishConfiguration)) {
257 if (isMac && isElectronUpdater1xCompatibility && event.file.endsWith(".zip")) {
258 // write only for first channel (generateUpdatesFilesForAllChannels is a new functionality, no need to generate old mac update info file)
259 isElectronUpdater1xCompatibility = false;
260 yield writeOldMacInfo(publishConfiguration, outDir, dir, channel, createdFiles, version, packager);
261 }
262
263 const updateInfoFile = path.join(dir, (isBintray ? `${version}_` : "") + getUpdateInfoFileName(channel, packager, event.arch));
264
265 if (createdFiles.has(updateInfoFile)) {
266 continue;
267 }
268
269 createdFiles.add(updateInfoFile); // artifact should be uploaded only to designated publish provider
270
271 tasks.push({
272 file: updateInfoFile,
273 info,
274 publishConfiguration,
275 packager
276 });
277 }
278 }
279
280 return tasks;
281 });
282
283 return function createUpdateInfoTasks(_x2, _x3) {
284 return _ref2.apply(this, arguments);
285 };
286})();
287
288exports.createUpdateInfoTasks = createUpdateInfoTasks;
289
290let writeUpdateInfoFiles = (() => {
291 var _ref4 = (0, _bluebirdLst().coroutine)(function* (updateInfoFileTasks, packager) {
292 // zip must be first and zip info must be used for old path/sha512 properties in the update info
293 updateInfoFileTasks.sort((a, b) => (a.info.files[0].url.endsWith(".zip") ? 0 : 100) - (b.info.files[0].url.endsWith(".zip") ? 0 : 100));
294 const updateChannelFileToInfo = new Map();
295
296 for (const task of updateInfoFileTasks) {
297 // https://github.com/electron-userland/electron-builder/pull/2994
298 const key = `${task.file}@${(0, _builderUtil().safeStringifyJson)(task.publishConfiguration, new Set(["releaseType"]))}`;
299 const existingTask = updateChannelFileToInfo.get(key);
300
301 if (existingTask == null) {
302 updateChannelFileToInfo.set(key, task);
303 continue;
304 }
305
306 existingTask.info.files.push(...task.info.files);
307 }
308
309 const releaseDate = new Date().toISOString();
310 yield _bluebirdLst().default.map(updateChannelFileToInfo.values(), (() => {
311 var _ref5 = (0, _bluebirdLst().coroutine)(function* (task) {
312 const publishConfig = task.publishConfiguration;
313
314 if (publishConfig.publishAutoUpdate === false) {
315 _builderUtil().log.debug({
316 provider: publishConfig.provider,
317 reason: "publishAutoUpdate is set to false"
318 }, "auto update metadata file not published");
319
320 return;
321 }
322
323 if (task.info.releaseDate == null) {
324 task.info.releaseDate = releaseDate;
325 }
326
327 const fileContent = Buffer.from((0, _builderUtil().serializeToYaml)(task.info));
328 yield (0, _fsExtraP().outputFile)(task.file, fileContent);
329 packager.dispatchArtifactCreated({
330 file: task.file,
331 fileContent,
332 arch: null,
333 packager: task.packager,
334 target: null,
335 publishConfig
336 });
337 });
338
339 return function (_x9) {
340 return _ref5.apply(this, arguments);
341 };
342 })(), {
343 concurrency: 4
344 });
345 });
346
347 return function writeUpdateInfoFiles(_x7, _x8) {
348 return _ref4.apply(this, arguments);
349 };
350})();
351
352exports.writeUpdateInfoFiles = writeUpdateInfoFiles;
353//# sourceMappingURL=updateInfoBuilder.js.map
\No newline at end of file