UNPKG

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