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