1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.createMacApp = void 0;
|
7 |
|
8 | function _bluebirdLst() {
|
9 | const data = _interopRequireWildcard(require("bluebird-lst"));
|
10 |
|
11 | _bluebirdLst = function () {
|
12 | return data;
|
13 | };
|
14 |
|
15 | return data;
|
16 | }
|
17 |
|
18 | function _builderUtil() {
|
19 | const data = require("builder-util");
|
20 |
|
21 | _builderUtil = function () {
|
22 | return data;
|
23 | };
|
24 |
|
25 | return data;
|
26 | }
|
27 |
|
28 | function _fs() {
|
29 | const data = require("builder-util/out/fs");
|
30 |
|
31 | _fs = function () {
|
32 | return data;
|
33 | };
|
34 |
|
35 | return data;
|
36 | }
|
37 |
|
38 | function _fsExtraP() {
|
39 | const data = require("fs-extra-p");
|
40 |
|
41 | _fsExtraP = function () {
|
42 | return data;
|
43 | };
|
44 |
|
45 | return data;
|
46 | }
|
47 |
|
48 | var path = _interopRequireWildcard(require("path"));
|
49 |
|
50 | function _plist() {
|
51 | const data = require("plist");
|
52 |
|
53 | _plist = function () {
|
54 | return data;
|
55 | };
|
56 |
|
57 | return data;
|
58 | }
|
59 |
|
60 | function _promise() {
|
61 | const data = require("builder-util/out/promise");
|
62 |
|
63 | _promise = function () {
|
64 | return data;
|
65 | };
|
66 |
|
67 | return data;
|
68 | }
|
69 |
|
70 | function _appInfo() {
|
71 | const data = require("../appInfo");
|
72 |
|
73 | _appInfo = function () {
|
74 | return data;
|
75 | };
|
76 |
|
77 | return data;
|
78 | }
|
79 |
|
80 | function _platformPackager() {
|
81 | const data = require("../platformPackager");
|
82 |
|
83 | _platformPackager = function () {
|
84 | return data;
|
85 | };
|
86 |
|
87 | return data;
|
88 | }
|
89 |
|
90 | 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; } }
|
91 |
|
92 | function doRename(basePath, oldName, newName) {
|
93 | return (0, _fsExtraP().rename)(path.join(basePath, oldName), path.join(basePath, newName));
|
94 | }
|
95 |
|
96 | function moveHelpers(frameworksPath, appName, prefix) {
|
97 | return _bluebirdLst().default.map([" Helper", " Helper EH", " Helper NP"], suffix => {
|
98 | const executableBasePath = path.join(frameworksPath, `${prefix}${suffix}.app`, "Contents", "MacOS");
|
99 | return doRename(executableBasePath, `${prefix}${suffix}`, appName + suffix).then(() => doRename(frameworksPath, `${prefix}${suffix}.app`, `${appName}${suffix}.app`));
|
100 | });
|
101 | }
|
102 |
|
103 |
|
104 |
|
105 | let createMacApp = (() => {
|
106 | var _ref = (0, _bluebirdLst().coroutine)(function* (packager, appOutDir, asarIntegrity) {
|
107 | const appInfo = packager.appInfo;
|
108 | const appFilename = appInfo.productFilename;
|
109 | const contentsPath = path.join(appOutDir, packager.info.framework.distMacOsAppName, "Contents");
|
110 | const frameworksPath = path.join(contentsPath, "Frameworks");
|
111 | const loginItemPath = path.join(contentsPath, "Library", "LoginItems");
|
112 | const appPlistFilename = path.join(contentsPath, "Info.plist");
|
113 | const helperPlistFilename = path.join(frameworksPath, `${packager.electronDistMacOsExecutableName} Helper.app`, "Contents", "Info.plist");
|
114 | const helperEHPlistFilename = path.join(frameworksPath, `${packager.electronDistMacOsExecutableName} Helper EH.app`, "Contents", "Info.plist");
|
115 | const helperNPPlistFilename = path.join(frameworksPath, `${packager.electronDistMacOsExecutableName} Helper NP.app`, "Contents", "Info.plist");
|
116 | const helperLoginPlistFilename = path.join(loginItemPath, `${packager.electronDistMacOsExecutableName} Login Helper.app`, "Contents", "Info.plist");
|
117 | const buildMetadata = packager.config;
|
118 | const fileContents = yield _bluebirdLst().default.map([appPlistFilename, helperPlistFilename, helperEHPlistFilename, helperNPPlistFilename, helperLoginPlistFilename, buildMetadata["extend-info"]], it => it == null ? it : (0, _promise().orIfFileNotExist)((0, _fsExtraP().readFile)(it, "utf8"), null));
|
119 | const appPlist = (0, _plist().parse)(fileContents[0]);
|
120 | const helperPlist = (0, _plist().parse)(fileContents[1]);
|
121 | const helperEHPlist = (0, _plist().parse)(fileContents[2]);
|
122 | const helperNPPlist = (0, _plist().parse)(fileContents[3]);
|
123 | const helperLoginPlist = fileContents[4] == null ? null : (0, _plist().parse)(fileContents[4]);
|
124 |
|
125 | if (fileContents[5] != null) {
|
126 | Object.assign(appPlist, (0, _plist().parse)(fileContents[5]));
|
127 | }
|
128 |
|
129 | const oldHelperBundleId = buildMetadata["helper-bundle-id"];
|
130 |
|
131 | if (oldHelperBundleId != null) {
|
132 | _builderUtil().log.warn("build.helper-bundle-id is deprecated, please set as build.mac.helperBundleId");
|
133 | }
|
134 |
|
135 | const helperBundleIdentifier = (0, _appInfo().filterCFBundleIdentifier)(packager.platformSpecificBuildOptions.helperBundleId || oldHelperBundleId || `${appInfo.macBundleIdentifier}.helper`);
|
136 | yield packager.applyCommonInfo(appPlist, contentsPath);
|
137 | helperPlist.CFBundleExecutable = `${appFilename} Helper`;
|
138 | helperEHPlist.CFBundleExecutable = `${appFilename} Helper EH`;
|
139 | helperNPPlist.CFBundleExecutable = `${appFilename} Helper NP`;
|
140 |
|
141 | if (helperLoginPlist != null) {
|
142 | helperLoginPlist.CFBundleExecutable = `${appFilename} Login Helper`;
|
143 | }
|
144 |
|
145 | helperPlist.CFBundleDisplayName = `${appInfo.productName} Helper`;
|
146 | helperEHPlist.CFBundleDisplayName = `${appInfo.productName} Helper EH`;
|
147 | helperNPPlist.CFBundleDisplayName = `${appInfo.productName} Helper NP`;
|
148 |
|
149 | if (helperLoginPlist != null) {
|
150 | helperLoginPlist.CFBundleDisplayName = `${appInfo.productName} Login Helper`;
|
151 | }
|
152 |
|
153 | helperPlist.CFBundleIdentifier = helperBundleIdentifier;
|
154 | helperEHPlist.CFBundleIdentifier = `${helperBundleIdentifier}.EH`;
|
155 | helperNPPlist.CFBundleIdentifier = `${helperBundleIdentifier}.NP`;
|
156 |
|
157 | if (helperLoginPlist != null) {
|
158 |
|
159 | helperLoginPlist.CFBundleIdentifier = `${appInfo.macBundleIdentifier}.loginhelper`;
|
160 | }
|
161 |
|
162 | helperPlist.CFBundleVersion = appPlist.CFBundleVersion;
|
163 | helperEHPlist.CFBundleVersion = appPlist.CFBundleVersion;
|
164 | helperNPPlist.CFBundleVersion = appPlist.CFBundleVersion;
|
165 |
|
166 | if (helperLoginPlist != null) {
|
167 | helperLoginPlist.CFBundleVersion = appPlist.CFBundleVersion;
|
168 | }
|
169 |
|
170 | const protocols = (0, _builderUtil().asArray)(buildMetadata.protocols).concat((0, _builderUtil().asArray)(packager.platformSpecificBuildOptions.protocols));
|
171 |
|
172 | if (protocols.length > 0) {
|
173 | appPlist.CFBundleURLTypes = protocols.map(protocol => {
|
174 | const schemes = (0, _builderUtil().asArray)(protocol.schemes);
|
175 |
|
176 | if (schemes.length === 0) {
|
177 | throw new (_builderUtil().InvalidConfigurationError)(`Protocol "${protocol.name}": must be at least one scheme specified`);
|
178 | }
|
179 |
|
180 | return {
|
181 | CFBundleURLName: protocol.name,
|
182 | CFBundleTypeRole: protocol.role || "Editor",
|
183 | CFBundleURLSchemes: schemes.slice()
|
184 | };
|
185 | });
|
186 | }
|
187 |
|
188 | const resourcesPath = path.join(contentsPath, "Resources");
|
189 | const fileAssociations = packager.fileAssociations;
|
190 |
|
191 | if (fileAssociations.length > 0) {
|
192 | appPlist.CFBundleDocumentTypes = yield _bluebirdLst().default.map(fileAssociations, (() => {
|
193 | var _ref2 = (0, _bluebirdLst().coroutine)(function* (fileAssociation) {
|
194 | const extensions = (0, _builderUtil().asArray)(fileAssociation.ext).map(_platformPackager().normalizeExt);
|
195 | const customIcon = yield packager.getResource((0, _builderUtil().getPlatformIconFileName)(fileAssociation.icon, true), `${extensions[0]}.icns`);
|
196 | let iconFile = appPlist.CFBundleIconFile;
|
197 |
|
198 | if (customIcon != null) {
|
199 | iconFile = path.basename(customIcon);
|
200 | yield (0, _fs().copyOrLinkFile)(customIcon, path.join(resourcesPath, iconFile));
|
201 | }
|
202 |
|
203 | const result = {
|
204 | CFBundleTypeExtensions: extensions,
|
205 | CFBundleTypeName: fileAssociation.name || extensions[0],
|
206 | CFBundleTypeRole: fileAssociation.role || "Editor",
|
207 | CFBundleTypeIconFile: iconFile
|
208 | };
|
209 |
|
210 | if (fileAssociation.isPackage) {
|
211 | result.LSTypeIsPackage = true;
|
212 | }
|
213 |
|
214 | return result;
|
215 | });
|
216 |
|
217 | return function (_x4) {
|
218 | return _ref2.apply(this, arguments);
|
219 | };
|
220 | })());
|
221 | }
|
222 |
|
223 | if (asarIntegrity != null) {
|
224 | appPlist.AsarIntegrity = JSON.stringify(asarIntegrity);
|
225 | }
|
226 |
|
227 | yield Promise.all([(0, _fsExtraP().writeFile)(appPlistFilename, (0, _plist().build)(appPlist)), (0, _fsExtraP().writeFile)(helperPlistFilename, (0, _plist().build)(helperPlist)), (0, _fsExtraP().writeFile)(helperEHPlistFilename, (0, _plist().build)(helperEHPlist)), (0, _fsExtraP().writeFile)(helperNPPlistFilename, (0, _plist().build)(helperNPPlist)), helperLoginPlist == null ? Promise.resolve() : (0, _fsExtraP().writeFile)(helperLoginPlistFilename, (0, _plist().build)(helperLoginPlist)), doRename(path.join(contentsPath, "MacOS"), packager.electronDistMacOsExecutableName, appPlist.CFBundleExecutable), (0, _fs().unlinkIfExists)(path.join(appOutDir, "LICENSE")), (0, _fs().unlinkIfExists)(path.join(appOutDir, "LICENSES.chromium.html"))]);
|
228 | yield moveHelpers(frameworksPath, appFilename, packager.electronDistMacOsExecutableName);
|
229 |
|
230 | if (helperLoginPlist != null) {
|
231 | const prefix = packager.electronDistMacOsExecutableName;
|
232 | const suffix = " Login Helper";
|
233 | const executableBasePath = path.join(loginItemPath, `${prefix}${suffix}.app`, "Contents", "MacOS");
|
234 | yield doRename(executableBasePath, `${prefix}${suffix}`, appFilename + suffix).then(() => doRename(loginItemPath, `${prefix}${suffix}.app`, `${appFilename}${suffix}.app`));
|
235 | }
|
236 |
|
237 | const appPath = path.join(appOutDir, `${appFilename}.app`);
|
238 | yield (0, _fsExtraP().rename)(path.dirname(contentsPath), appPath);
|
239 |
|
240 | const now = Date.now() / 1000;
|
241 | yield (0, _fsExtraP().utimes)(appPath, now, now);
|
242 | });
|
243 |
|
244 | return function createMacApp(_x, _x2, _x3) {
|
245 | return _ref.apply(this, arguments);
|
246 | };
|
247 | })(); exports.createMacApp = createMacApp;
|
248 |
|
\ | No newline at end of file |