1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.expandMacro = void 0;
|
4 | const builder_util_1 = require("builder-util");
|
5 | function expandMacro(pattern, arch, appInfo, extra = {}, isProductNameSanitized = true) {
|
6 | if (arch == null) {
|
7 | pattern = pattern
|
8 |
|
9 | .replace("-${arch}", "")
|
10 |
|
11 | .replace(" ${arch}", "")
|
12 |
|
13 | .replace("_${arch}", "")
|
14 |
|
15 | .replace("/${arch}", "");
|
16 | }
|
17 | return pattern.replace(/\${([_a-zA-Z./*+]+)}/g, (match, p1) => {
|
18 | switch (p1) {
|
19 | case "productName":
|
20 | return isProductNameSanitized ? appInfo.sanitizedProductName : appInfo.productName;
|
21 | case "arch":
|
22 | if (arch == null) {
|
23 |
|
24 | return "";
|
25 | }
|
26 | return arch;
|
27 | case "author": {
|
28 | const companyName = appInfo.companyName;
|
29 | if (companyName == null) {
|
30 | throw new builder_util_1.InvalidConfigurationError(`cannot expand pattern "${pattern}": author is not specified`, "ERR_ELECTRON_BUILDER_AUTHOR_UNSPECIFIED");
|
31 | }
|
32 | return companyName;
|
33 | }
|
34 | case "platform":
|
35 | return process.platform;
|
36 | case "channel":
|
37 | return appInfo.channel || "latest";
|
38 | default: {
|
39 | if (p1 in appInfo) {
|
40 | return appInfo[p1];
|
41 | }
|
42 | if (p1.startsWith("env.")) {
|
43 | const envName = p1.substring("env.".length);
|
44 | const envValue = process.env[envName];
|
45 | if (envValue == null) {
|
46 | throw new builder_util_1.InvalidConfigurationError(`cannot expand pattern "${pattern}": env ${envName} is not defined`, "ERR_ELECTRON_BUILDER_ENV_NOT_DEFINED");
|
47 | }
|
48 | return envValue;
|
49 | }
|
50 | const value = extra[p1];
|
51 | if (value == null) {
|
52 | throw new builder_util_1.InvalidConfigurationError(`cannot expand pattern "${pattern}": macro ${p1} is not defined`, "ERR_ELECTRON_BUILDER_MACRO_NOT_DEFINED");
|
53 | }
|
54 | else {
|
55 | return value;
|
56 | }
|
57 | }
|
58 | }
|
59 | });
|
60 | }
|
61 | exports.expandMacro = expandMacro;
|
62 |
|
\ | No newline at end of file |