UNPKG

27.4 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.isSafeGithubName = isSafeGithubName;
7exports.normalizeExt = normalizeExt;
8exports.resolveFunction = resolveFunction;
9exports.chooseNotNull = chooseNotNull;
10exports.PlatformPackager = void 0;
11
12function _bluebirdLst() {
13 const data = _interopRequireWildcard(require("bluebird-lst"));
14
15 _bluebirdLst = function () {
16 return data;
17 };
18
19 return data;
20}
21
22function _builderUtil() {
23 const data = require("builder-util");
24
25 _builderUtil = function () {
26 return data;
27 };
28
29 return data;
30}
31
32function _fs() {
33 const data = require("builder-util/out/fs");
34
35 _fs = function () {
36 return data;
37 };
38
39 return data;
40}
41
42function _promise() {
43 const data = require("builder-util/out/promise");
44
45 _promise = function () {
46 return data;
47 };
48
49 return data;
50}
51
52function _fsExtraP() {
53 const data = require("fs-extra-p");
54
55 _fsExtraP = function () {
56 return data;
57 };
58
59 return data;
60}
61
62function _lazyVal() {
63 const data = require("lazy-val");
64
65 _lazyVal = function () {
66 return data;
67 };
68
69 return data;
70}
71
72var path = _interopRequireWildcard(require("path"));
73
74function _asarFileChecker() {
75 const data = require("./asar/asarFileChecker");
76
77 _asarFileChecker = function () {
78 return data;
79 };
80
81 return data;
82}
83
84function _asarUtil() {
85 const data = require("./asar/asarUtil");
86
87 _asarUtil = function () {
88 return data;
89 };
90
91 return data;
92}
93
94function _integrity() {
95 const data = require("./asar/integrity");
96
97 _integrity = function () {
98 return data;
99 };
100
101 return data;
102}
103
104function _fileMatcher() {
105 const data = require("./fileMatcher");
106
107 _fileMatcher = function () {
108 return data;
109 };
110
111 return data;
112}
113
114function _fileTransformer() {
115 const data = require("./fileTransformer");
116
117 _fileTransformer = function () {
118 return data;
119 };
120
121 return data;
122}
123
124function _Framework() {
125 const data = require("./Framework");
126
127 _Framework = function () {
128 return data;
129 };
130
131 return data;
132}
133
134function _index() {
135 const data = require("./index");
136
137 _index = function () {
138 return data;
139 };
140
141 return data;
142}
143
144function _appFileCopier() {
145 const data = require("./util/appFileCopier");
146
147 _appFileCopier = function () {
148 return data;
149 };
150
151 return data;
152}
153
154function _macroExpander() {
155 const data = require("./util/macroExpander");
156
157 _macroExpander = function () {
158 return data;
159 };
160
161 return data;
162}
163
164function _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; } }
165
166class PlatformPackager {
167 constructor(info, platform) {
168 this.info = info;
169 this.platform = platform;
170 this._resourceList = new (_lazyVal().Lazy)(() => (0, _promise().orIfFileNotExist)((0, _fsExtraP().readdir)(this.info.buildResourcesDir), []));
171 this.platformSpecificBuildOptions = PlatformPackager.normalizePlatformSpecificBuildOptions(this.config[platform.buildConfigurationKey]);
172 this.appInfo = this.prepareAppInfo(info.appInfo);
173 }
174
175 get packagerOptions() {
176 return this.info.options;
177 }
178
179 get buildResourcesDir() {
180 return this.info.buildResourcesDir;
181 }
182
183 get projectDir() {
184 return this.info.projectDir;
185 }
186
187 get config() {
188 return this.info.config;
189 }
190
191 get resourceList() {
192 return this._resourceList.value;
193 }
194
195 get compression() {
196 const compression = this.platformSpecificBuildOptions.compression; // explicitly set to null - request to use default value instead of parent (in the config)
197
198 if (compression === null) {
199 return "normal";
200 }
201
202 return compression || this.config.compression || "normal";
203 }
204
205 get debugLogger() {
206 return this.info.debugLogger;
207 }
208
209 prepareAppInfo(appInfo) {
210 return appInfo;
211 }
212
213 static normalizePlatformSpecificBuildOptions(options) {
214 return options == null ? Object.create(null) : options;
215 }
216
217 getCscPassword() {
218 const password = this.doGetCscPassword();
219
220 if ((0, _builderUtil().isEmptyOrSpaces)(password)) {
221 _builderUtil().log.info({
222 reason: "CSC_KEY_PASSWORD is not defined"
223 }, "empty password will be used for code signing");
224
225 return "";
226 } else {
227 return password.trim();
228 }
229 }
230
231 getCscLink(extraEnvName) {
232 // allow to specify as empty string
233 const envValue = chooseNotNull(extraEnvName == null ? null : process.env[extraEnvName], process.env.CSC_LINK);
234 return chooseNotNull(chooseNotNull(this.info.config.cscLink, this.platformSpecificBuildOptions.cscLink), envValue);
235 }
236
237 doGetCscPassword() {
238 // allow to specify as empty string
239 return chooseNotNull(chooseNotNull(this.info.config.cscKeyPassword, this.platformSpecificBuildOptions.cscKeyPassword), process.env.CSC_KEY_PASSWORD);
240 }
241
242 computeAppOutDir(outDir, arch) {
243 return this.packagerOptions.prepackaged || path.join(outDir, `${this.platform.buildConfigurationKey}${(0, _builderUtil().getArchSuffix)(arch)}${this.platform === _index().Platform.MAC ? "" : "-unpacked"}`);
244 }
245
246 dispatchArtifactCreated(file, target, arch, safeArtifactName) {
247 this.info.dispatchArtifactCreated({
248 file,
249 safeArtifactName,
250 target,
251 arch,
252 packager: this
253 });
254 }
255
256 pack(outDir, arch, targets, taskManager) {
257 var _this = this;
258
259 return (0, _bluebirdLst().coroutine)(function* () {
260 const appOutDir = _this.computeAppOutDir(outDir, arch);
261
262 yield _this.doPack(outDir, appOutDir, _this.platform.nodeName, arch, _this.platformSpecificBuildOptions, targets);
263
264 _this.packageInDistributableFormat(appOutDir, arch, targets, taskManager);
265 })();
266 }
267
268 packageInDistributableFormat(appOutDir, arch, targets, taskManager) {
269 var _this2 = this;
270
271 if (targets.find(it => !it.isAsyncSupported) == null) {
272 PlatformPackager.buildAsyncTargets(targets, taskManager, appOutDir, arch);
273 return;
274 }
275
276 taskManager.add((0, _bluebirdLst().coroutine)(function* () {
277 // BluebirdPromise.map doesn't invoke target.build immediately, but for RemoteTarget it is very critical to call build() before finishBuild()
278 const subTaskManager = new (_builderUtil().AsyncTaskManager)(_this2.info.cancellationToken);
279 PlatformPackager.buildAsyncTargets(targets, subTaskManager, appOutDir, arch);
280 yield subTaskManager.awaitTasks();
281
282 for (const target of targets) {
283 if (!target.isAsyncSupported) {
284 yield target.build(appOutDir, arch);
285 }
286 }
287 }));
288 }
289
290 static buildAsyncTargets(targets, taskManager, appOutDir, arch) {
291 for (const target of targets) {
292 if (target.isAsyncSupported) {
293 taskManager.addTask(target.build(appOutDir, arch));
294 }
295 }
296 }
297
298 getExtraFileMatchers(isResources, appOutDir, options) {
299 const base = isResources ? this.getResourcesDir(appOutDir) : this.platform === _index().Platform.MAC ? path.join(appOutDir, `${this.appInfo.productFilename}.app`, "Contents") : appOutDir;
300 return (0, _fileMatcher().getFileMatchers)(this.config, isResources ? "extraResources" : "extraFiles", this.projectDir, base, options);
301 }
302
303 get electronDistExecutableName() {
304 return this.config.muonVersion == null ? "electron" : "brave";
305 }
306
307 get electronDistMacOsExecutableName() {
308 return this.config.muonVersion == null ? "Electron" : "Brave";
309 }
310
311 doPack(outDir, appOutDir, platformName, arch, platformSpecificBuildOptions, targets) {
312 var _this3 = this;
313
314 return (0, _bluebirdLst().coroutine)(function* () {
315 if (_this3.packagerOptions.prepackaged != null) {
316 return;
317 }
318
319 const macroExpander = it => _this3.expandMacro(it, arch == null ? null : _builderUtil().Arch[arch], {
320 "/*": "{,/**/*}"
321 });
322
323 const framework = _this3.info.framework;
324
325 _builderUtil().log.info({
326 platform: platformName,
327 arch: _builderUtil().Arch[arch],
328 [`${framework.name}`]: framework.version,
329 appOutDir: _builderUtil().log.filePath(appOutDir)
330 }, `packaging`);
331
332 yield framework.prepareApplicationStageDirectory({
333 packager: _this3,
334 appOutDir,
335 platformName,
336 arch: _builderUtil().Arch[arch],
337 version: framework.version
338 });
339 const excludePatterns = [];
340
341 const computeParsedPatterns = patterns => {
342 if (patterns != null) {
343 for (const pattern of patterns) {
344 pattern.computeParsedPatterns(excludePatterns, _this3.info.projectDir);
345 }
346 }
347 };
348
349 const getFileMatchersOptions = {
350 macroExpander,
351 customBuildOptions: platformSpecificBuildOptions,
352 outDir
353 };
354
355 const extraResourceMatchers = _this3.getExtraFileMatchers(true, appOutDir, getFileMatchersOptions);
356
357 computeParsedPatterns(extraResourceMatchers);
358
359 const extraFileMatchers = _this3.getExtraFileMatchers(false, appOutDir, getFileMatchersOptions);
360
361 computeParsedPatterns(extraFileMatchers);
362 const packContext = {
363 appOutDir,
364 outDir,
365 arch,
366 targets,
367 packager: _this3,
368 electronPlatformName: platformName
369 };
370 const asarOptions = yield _this3.computeAsarOptions(platformSpecificBuildOptions);
371 const resourcesPath = _this3.platform === _index().Platform.MAC ? path.join(appOutDir, framework.distMacOsAppName, "Contents", "Resources") : (0, _Framework().isElectronBased)(framework) ? path.join(appOutDir, "resources") : appOutDir;
372 const taskManager = new (_builderUtil().AsyncTaskManager)(_this3.info.cancellationToken);
373
374 _this3.copyAppFiles(taskManager, asarOptions, resourcesPath, path.join(resourcesPath, "app"), packContext, platformSpecificBuildOptions, excludePatterns, macroExpander);
375
376 yield taskManager.awaitTasks();
377
378 if (_this3.info.cancellationToken.cancelled) {
379 return;
380 }
381
382 const beforeCopyExtraFiles = _this3.info.framework.beforeCopyExtraFiles;
383
384 if (beforeCopyExtraFiles != null) {
385 yield beforeCopyExtraFiles(_this3, appOutDir, asarOptions == null ? null : yield (0, _integrity().computeData)(resourcesPath, asarOptions.externalAllowed ? {
386 externalAllowed: true
387 } : null));
388 }
389
390 const transformerForExtraFiles = _this3.createTransformerForExtraFiles(packContext);
391
392 yield (0, _fileMatcher().copyFiles)(extraResourceMatchers, transformerForExtraFiles);
393 yield (0, _fileMatcher().copyFiles)(extraFileMatchers, transformerForExtraFiles);
394
395 if (_this3.info.cancellationToken.cancelled) {
396 return;
397 }
398
399 yield _this3.info.afterPack(packContext);
400 const isAsar = asarOptions != null;
401 yield _this3.sanityCheckPackage(appOutDir, isAsar);
402 yield _this3.signApp(packContext, isAsar);
403 const afterSign = resolveFunction(_this3.config.afterSign, "afterSign");
404
405 if (afterSign != null) {
406 yield Promise.resolve(afterSign(packContext));
407 }
408 })();
409 }
410
411 createTransformerForExtraFiles(packContext) {
412 return null;
413 }
414
415 copyAppFiles(taskManager, asarOptions, resourcePath, defaultDestination, packContext, platformSpecificBuildOptions, excludePatterns, macroExpander) {
416 var _this4 = this;
417
418 const appDir = this.info.appDir;
419 const config = this.config;
420 const isElectronCompile = asarOptions != null && (0, _fileTransformer().isElectronCompileUsed)(this.info);
421 const mainMatchers = (0, _fileMatcher().getMainFileMatchers)(appDir, defaultDestination, macroExpander, platformSpecificBuildOptions, this, packContext.outDir, isElectronCompile);
422
423 if (excludePatterns.length > 0) {
424 for (const matcher of mainMatchers) {
425 matcher.excludePatterns = excludePatterns;
426 }
427 }
428
429 const framework = this.info.framework;
430 const transformer = (0, _fileTransformer().createTransformer)(appDir, config, isElectronCompile ? Object.assign({
431 originalMain: this.info.metadata.main,
432 main: _appFileCopier().ELECTRON_COMPILE_SHIM_FILENAME
433 }, config.extraMetadata) : config.extraMetadata, framework.createTransformer == null ? null : framework.createTransformer());
434
435 const _computeFileSets = matchers => {
436 return (0, _appFileCopier().computeFileSets)(matchers, this.info.isPrepackedAppAsar ? null : transformer, this, isElectronCompile).then((() => {
437 var _ref2 = (0, _bluebirdLst().coroutine)(function* (result) {
438 if (!_this4.info.isPrepackedAppAsar && !_this4.info.areNodeModulesHandledExternally) {
439 const moduleFileMatcher = (0, _fileMatcher().getNodeModuleFileMatcher)(appDir, defaultDestination, macroExpander, platformSpecificBuildOptions, _this4.info);
440 result = result.concat((yield (0, _appFileCopier().computeNodeModuleFileSets)(_this4, moduleFileMatcher)));
441 }
442
443 return result.filter(it => it.files.length > 0);
444 });
445
446 return function (_x) {
447 return _ref2.apply(this, arguments);
448 };
449 })());
450 };
451
452 if (this.info.isPrepackedAppAsar) {
453 taskManager.addTask(_bluebirdLst().default.each(_computeFileSets([new (_fileMatcher().FileMatcher)(appDir, resourcePath, macroExpander)]), it => (0, _appFileCopier().copyAppFiles)(it, this.info, transformer)));
454 } else if (asarOptions == null) {
455 // for ASAR all asar unpacked files will be extra transformed (e.g. sign of EXE and DLL) later,
456 // for prepackaged asar extra transformation not supported yet,
457 // so, extra transform if asar is disabled
458 const transformerForExtraFiles = this.createTransformerForExtraFiles(packContext);
459
460 const combinedTransformer = file => {
461 if (transformerForExtraFiles != null) {
462 const result = transformerForExtraFiles(file);
463
464 if (result != null) {
465 return result;
466 }
467 }
468
469 return transformer(file);
470 };
471
472 taskManager.addTask(_bluebirdLst().default.each(_computeFileSets(mainMatchers), it => (0, _appFileCopier().copyAppFiles)(it, this.info, combinedTransformer)));
473 } else {
474 const unpackPattern = (0, _fileMatcher().getFileMatchers)(config, "asarUnpack", appDir, defaultDestination, {
475 macroExpander,
476 customBuildOptions: platformSpecificBuildOptions,
477 outDir: packContext.outDir
478 });
479 const fileMatcher = unpackPattern == null ? null : unpackPattern[0];
480 taskManager.addTask(_computeFileSets(mainMatchers).then((() => {
481 var _ref3 = (0, _bluebirdLst().coroutine)(function* (fileSets) {
482 for (const fileSet of fileSets) {
483 yield (0, _appFileCopier().transformFiles)(transformer, fileSet);
484 }
485
486 yield new (_asarUtil().AsarPackager)(appDir, resourcePath, asarOptions, fileMatcher == null ? null : fileMatcher.createFilter()).pack(fileSets, _this4);
487 });
488
489 return function (_x2) {
490 return _ref3.apply(this, arguments);
491 };
492 })()));
493 }
494 }
495
496 signApp(packContext, isAsar) {
497 return Promise.resolve();
498 }
499
500 getIconPath() {
501 return (0, _bluebirdLst().coroutine)(function* () {
502 return null;
503 })();
504 }
505
506 computeAsarOptions(customBuildOptions) {
507 var _this5 = this;
508
509 return (0, _bluebirdLst().coroutine)(function* () {
510 if (!(0, _Framework().isElectronBased)(_this5.info.framework)) {
511 return null;
512 }
513
514 function errorMessage(name) {
515 return `${name} is deprecated is deprecated and not supported — please use asarUnpack`;
516 }
517
518 const buildMetadata = _this5.config;
519
520 if (buildMetadata["asar-unpack"] != null) {
521 throw new Error(errorMessage("asar-unpack"));
522 }
523
524 if (buildMetadata["asar-unpack-dir"] != null) {
525 throw new Error(errorMessage("asar-unpack-dir"));
526 }
527
528 const platformSpecific = customBuildOptions.asar;
529 const result = platformSpecific == null ? _this5.config.asar : platformSpecific;
530
531 if (result === false) {
532 const appAsarStat = yield (0, _fs().statOrNull)(path.join(_this5.info.appDir, "app.asar")); //noinspection ES6MissingAwait
533
534 if (appAsarStat == null || !appAsarStat.isFile()) {
535 _builderUtil().log.warn({
536 solution: "enable asar and use asarUnpack to unpack files that must be externally available"
537 }, "asar using is disabled — it is strongly not recommended");
538 }
539
540 return null;
541 }
542
543 if (result == null || result === true) {
544 return {};
545 }
546
547 for (const name of ["unpackDir", "unpack"]) {
548 if (result[name] != null) {
549 throw new Error(errorMessage(`asar.${name}`));
550 }
551 }
552
553 return (0, _builderUtil().deepAssign)({}, result);
554 })();
555 }
556
557 getElectronSrcDir(dist) {
558 return path.resolve(this.projectDir, dist);
559 }
560
561 getElectronDestinationDir(appOutDir) {
562 return appOutDir;
563 }
564
565 getResourcesDir(appOutDir) {
566 if (this.platform === _index().Platform.MAC) {
567 return this.getMacOsResourcesDir(appOutDir);
568 } else if ((0, _Framework().isElectronBased)(this.info.framework)) {
569 return path.join(appOutDir, "resources");
570 } else {
571 return appOutDir;
572 }
573 }
574
575 getMacOsResourcesDir(appOutDir) {
576 return path.join(appOutDir, `${this.appInfo.productFilename}.app`, "Contents", "Resources");
577 }
578
579 checkFileInPackage(resourcesDir, file, messagePrefix, isAsar) {
580 var _this6 = this;
581
582 return (0, _bluebirdLst().coroutine)(function* () {
583 const relativeFile = path.relative(_this6.info.appDir, path.resolve(_this6.info.appDir, file));
584
585 if (isAsar) {
586 yield (0, _asarFileChecker().checkFileInArchive)(path.join(resourcesDir, "app.asar"), relativeFile, messagePrefix);
587 return;
588 }
589
590 const pathParsed = path.parse(file); // Even when packaging to asar is disabled, it does not imply that the main file can not be inside an .asar archive.
591 // This may occur when the packaging is done manually before processing with electron-builder.
592
593 if (pathParsed.dir.includes(".asar")) {
594 // The path needs to be split to the part with an asar archive which acts like a directory and the part with
595 // the path to main file itself. (e.g. path/arch.asar/dir/index.js -> path/arch.asar, dir/index.js)
596 // noinspection TypeScriptValidateJSTypes
597 const pathSplit = pathParsed.dir.split(path.sep);
598 let partWithAsarIndex = 0;
599 pathSplit.some((pathPart, index) => {
600 partWithAsarIndex = index;
601 return pathPart.endsWith(".asar");
602 });
603 const asarPath = path.join.apply(path, pathSplit.slice(0, partWithAsarIndex + 1));
604 let mainPath = pathSplit.length > partWithAsarIndex + 1 ? path.join.apply(pathSplit.slice(partWithAsarIndex + 1)) : "";
605 mainPath += path.join(mainPath, pathParsed.base);
606 yield (0, _asarFileChecker().checkFileInArchive)(path.join(resourcesDir, "app", asarPath), mainPath, messagePrefix);
607 } else {
608 const outStat = yield (0, _fs().statOrNull)(path.join(resourcesDir, "app", relativeFile));
609
610 if (outStat == null) {
611 throw new Error(`${messagePrefix} "${relativeFile}" does not exist. Seems like a wrong configuration.`);
612 } else {
613 //noinspection ES6MissingAwait
614 if (!outStat.isFile()) {
615 throw new Error(`${messagePrefix} "${relativeFile}" is not a file. Seems like a wrong configuration.`);
616 }
617 }
618 }
619 })();
620 }
621
622 sanityCheckPackage(appOutDir, isAsar) {
623 var _this7 = this;
624
625 return (0, _bluebirdLst().coroutine)(function* () {
626 const outStat = yield (0, _fs().statOrNull)(appOutDir);
627
628 if (outStat == null) {
629 throw new Error(`Output directory "${appOutDir}" does not exist. Seems like a wrong configuration.`);
630 } else {
631 //noinspection ES6MissingAwait
632 if (!outStat.isDirectory()) {
633 throw new Error(`Output directory "${appOutDir}" is not a directory. Seems like a wrong configuration.`);
634 }
635 }
636
637 const resourcesDir = _this7.getResourcesDir(appOutDir);
638
639 yield _this7.checkFileInPackage(resourcesDir, _this7.info.metadata.main || "index.js", "Application entry file", isAsar);
640 yield _this7.checkFileInPackage(resourcesDir, "package.json", "Application", isAsar);
641 })();
642 } // tslint:disable-next-line:no-invalid-template-strings
643
644
645 computeSafeArtifactName(suggestedName, ext, arch, skipArchIfX64 = true, safePattern = "${name}-${version}-${arch}.${ext}") {
646 // GitHub only allows the listed characters in file names.
647 if (suggestedName != null && isSafeGithubName(suggestedName)) {
648 return null;
649 }
650
651 return this.computeArtifactName(safePattern, ext, skipArchIfX64 && arch === _builderUtil().Arch.x64 ? null : arch);
652 }
653
654 expandArtifactNamePattern(targetSpecificOptions, ext, arch, defaultPattern, skipArchIfX64 = true) {
655 let pattern = targetSpecificOptions == null ? null : targetSpecificOptions.artifactName;
656
657 if (pattern == null) {
658 // tslint:disable-next-line:no-invalid-template-strings
659 pattern = this.platformSpecificBuildOptions.artifactName || this.config.artifactName || defaultPattern || "${productName}-${version}-${arch}.${ext}";
660 }
661
662 return this.computeArtifactName(pattern, ext, skipArchIfX64 && arch === _builderUtil().Arch.x64 ? null : arch);
663 }
664
665 computeArtifactName(pattern, ext, arch) {
666 let archName = arch == null ? null : _builderUtil().Arch[arch];
667
668 if (arch === _builderUtil().Arch.x64) {
669 if (ext === "AppImage" || ext === "rpm") {
670 archName = "x86_64";
671 } else if (ext === "deb" || ext === "snap") {
672 archName = "amd64";
673 }
674 } else if (arch === _builderUtil().Arch.ia32) {
675 if (ext === "deb" || ext === "AppImage" || ext === "snap") {
676 archName = "i386";
677 } else if (ext === "pacman" || ext === "rpm") {
678 archName = "i686";
679 }
680 }
681
682 return this.expandMacro(pattern, this.platform === _index().Platform.MAC ? null : archName, {
683 ext
684 });
685 }
686
687 expandMacro(pattern, arch, extra = {}, isProductNameSanitized = true) {
688 return (0, _macroExpander().expandMacro)(pattern, arch, this.appInfo, Object.assign({
689 os: this.platform.buildConfigurationKey
690 }, extra), isProductNameSanitized);
691 }
692
693 generateName2(ext, classifier, deployment) {
694 const dotExt = ext == null ? "" : `.${ext}`;
695 const separator = ext === "deb" ? "_" : "-";
696 return `${deployment ? this.appInfo.name : this.appInfo.productFilename}${separator}${this.appInfo.version}${classifier == null ? "" : `${separator}${classifier}`}${dotExt}`;
697 }
698
699 getTempFile(suffix) {
700 return this.info.tempDirManager.getTempFile({
701 suffix
702 });
703 }
704
705 get fileAssociations() {
706 return (0, _builderUtil().asArray)(this.config.fileAssociations).concat((0, _builderUtil().asArray)(this.platformSpecificBuildOptions.fileAssociations));
707 }
708
709 getResource(custom, ...names) {
710 var _this8 = this;
711
712 return (0, _bluebirdLst().coroutine)(function* () {
713 const resourcesDir = _this8.info.buildResourcesDir;
714
715 if (custom === undefined) {
716 const resourceList = yield _this8.resourceList;
717
718 for (const name of names) {
719 if (resourceList.includes(name)) {
720 return path.join(resourcesDir, name);
721 }
722 }
723 } else if (custom != null && !(0, _builderUtil().isEmptyOrSpaces)(custom)) {
724 const resourceList = yield _this8.resourceList;
725
726 if (resourceList.includes(custom)) {
727 return path.join(resourcesDir, custom);
728 }
729
730 let p = path.resolve(resourcesDir, custom);
731
732 if ((yield (0, _fs().statOrNull)(p)) == null) {
733 p = path.resolve(_this8.projectDir, custom);
734
735 if ((yield (0, _fs().statOrNull)(p)) == null) {
736 throw new (_builderUtil().InvalidConfigurationError)(`cannot find specified resource "${custom}", nor relative to "${resourcesDir}", neither relative to project dir ("${_this8.projectDir}")`);
737 }
738 }
739
740 return p;
741 }
742
743 return null;
744 })();
745 }
746
747 get forceCodeSigning() {
748 const forceCodeSigningPlatform = this.platformSpecificBuildOptions.forceCodeSigning;
749 return (forceCodeSigningPlatform == null ? this.config.forceCodeSigning : forceCodeSigningPlatform) || false;
750 }
751
752 getOrConvertIcon(format) {
753 var _this9 = this;
754
755 return (0, _bluebirdLst().coroutine)(function* () {
756 const sourceNames = [`icon.${format === "set" ? "png" : format}`, "icon.png", "icons"];
757 const iconPath = _this9.platformSpecificBuildOptions.icon || _this9.config.icon;
758
759 if (iconPath != null) {
760 sourceNames.unshift(iconPath);
761 }
762
763 if (format === "ico") {
764 sourceNames.push("icon.icns");
765 }
766
767 const result = yield _this9.resolveIcon(sourceNames, format);
768
769 if (result.length === 0) {
770 const framework = _this9.info.framework;
771
772 if (framework.getDefaultIcon != null) {
773 return framework.getDefaultIcon(_this9.platform);
774 }
775
776 _builderUtil().log.warn({
777 reason: "application icon is not set"
778 }, framework.isDefaultAppIconProvided ? `default ${capitalizeFirstLetter(framework.name)} icon is used` : `application doesn't have an icon`);
779
780 return null;
781 } else {
782 return result[0].file;
783 }
784 })();
785 } // convert if need, validate size (it is a reason why tool is called even if file has target extension (already specified as foo.icns for example))
786
787
788 resolveIcon(sources, outputFormat) {
789 var _this10 = this;
790
791 return (0, _bluebirdLst().coroutine)(function* () {
792 const args = ["icon", "--format", outputFormat, "--root", _this10.buildResourcesDir, "--root", _this10.projectDir, "--out", path.resolve(_this10.projectDir, _this10.config.directories.output, `.icon-${outputFormat}`)];
793
794 for (const source of sources) {
795 args.push("--input", source);
796 }
797
798 const result = yield (0, _builderUtil().executeAppBuilderAsJson)(args);
799 const errorMessage = result.error;
800
801 if (errorMessage != null) {
802 throw new (_builderUtil().InvalidConfigurationError)(errorMessage, result.errorCode);
803 }
804
805 return result.icons || [];
806 })();
807 }
808
809}
810
811exports.PlatformPackager = PlatformPackager;
812
813function isSafeGithubName(name) {
814 return /^[0-9A-Za-z._-]+$/.test(name);
815} // remove leading dot
816
817
818function normalizeExt(ext) {
819 return ext.startsWith(".") ? ext.substring(1) : ext;
820}
821
822function resolveFunction(executor, name) {
823 if (executor == null || typeof executor !== "string") {
824 return executor;
825 }
826
827 let p = executor;
828
829 if (p.startsWith(".")) {
830 p = path.resolve(p);
831 }
832
833 try {
834 p = require.resolve(p);
835 } catch (e) {
836 (0, _builderUtil().debug)(e);
837 p = path.resolve(p);
838 }
839
840 const m = require(p);
841
842 const namedExport = m[name];
843
844 if (namedExport == null) {
845 return m.default || m;
846 } else {
847 return namedExport;
848 }
849}
850
851function chooseNotNull(v1, v2) {
852 return v1 == null ? v2 : v1;
853}
854
855function capitalizeFirstLetter(text) {
856 return text.charAt(0).toUpperCase() + text.slice(1);
857}
858//# sourceMappingURL=platformPackager.js.map
\No newline at end of file