UNPKG

8.4 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.prepareProductBuildArgs = prepareProductBuildArgs;
7exports.PkgTarget = void 0;
8
9function _bluebirdLst() {
10 const data = require("bluebird-lst");
11
12 _bluebirdLst = function () {
13 return data;
14 };
15
16 return data;
17}
18
19function _builderUtil() {
20 const data = require("builder-util");
21
22 _builderUtil = function () {
23 return data;
24 };
25
26 return data;
27}
28
29function _fs() {
30 const data = require("builder-util/out/fs");
31
32 _fs = function () {
33 return data;
34 };
35
36 return data;
37}
38
39function _license() {
40 const data = require("../util/license");
41
42 _license = function () {
43 return data;
44 };
45
46 return data;
47}
48
49function _fsExtraP() {
50 const data = require("fs-extra-p");
51
52 _fsExtraP = function () {
53 return data;
54 };
55
56 return data;
57}
58
59var path = _interopRequireWildcard(require("path"));
60
61function _plist() {
62 const data = require("plist");
63
64 _plist = function () {
65 return data;
66 };
67
68 return data;
69}
70
71function _appInfo() {
72 const data = require("../appInfo");
73
74 _appInfo = function () {
75 return data;
76 };
77
78 return data;
79}
80
81function _codeSign() {
82 const data = require("../codeSign");
83
84 _codeSign = function () {
85 return data;
86 };
87
88 return data;
89}
90
91function _core() {
92 const data = require("../core");
93
94 _core = function () {
95 return data;
96 };
97
98 return data;
99}
100
101function _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; } }
102
103const certType = "Developer ID Installer"; // http://www.shanekirk.com/2013/10/creating-flat-packages-in-osx/
104// to use --scripts, we must build .app bundle separately using pkgbuild
105// productbuild --scripts doesn't work (because scripts in this case not added to our package)
106// https://github.com/electron-userland/electron-osx-sign/issues/96#issuecomment-274986942
107
108class PkgTarget extends _core().Target {
109 constructor(packager, outDir) {
110 super("pkg");
111 this.packager = packager;
112 this.outDir = outDir;
113 this.options = Object.assign({
114 allowAnywhere: true,
115 allowCurrentUserHome: true,
116 allowRootDirectory: true
117 }, this.packager.config.pkg);
118 }
119
120 build(appPath, arch) {
121 var _this = this;
122
123 return (0, _bluebirdLst().coroutine)(function* () {
124 const packager = _this.packager;
125 const options = _this.options;
126 const appInfo = packager.appInfo;
127 const artifactName = packager.expandArtifactNamePattern(options, "pkg");
128 const artifactPath = path.join(_this.outDir, artifactName);
129
130 _this.logBuilding("pkg", artifactPath, arch);
131
132 const keychainName = (yield packager.codeSigningInfo.value).keychainName;
133 const appOutDir = _this.outDir; // https://developer.apple.com/library/content/documentation/DeveloperTools/Reference/DistributionDefinitionRef/Chapters/Distribution_XML_Ref.html
134
135 const distInfoFile = path.join(appOutDir, "distribution.xml");
136 const innerPackageFile = path.join(appOutDir, `${(0, _appInfo().filterCFBundleIdentifier)(appInfo.id)}.pkg`);
137 const componentPropertyListFile = path.join(appOutDir, `${(0, _appInfo().filterCFBundleIdentifier)(appInfo.id)}.plist`);
138 const identity = (yield Promise.all([(0, _codeSign().findIdentity)(certType, options.identity || packager.platformSpecificBuildOptions.identity, keychainName), _this.customizeDistributionConfiguration(distInfoFile, appPath), _this.buildComponentPackage(appPath, componentPropertyListFile, innerPackageFile)]))[0];
139
140 if (identity == null && packager.forceCodeSigning) {
141 throw new Error(`Cannot find valid "${certType}" to sign standalone installer, please see https://electron.build/code-signing`);
142 }
143
144 const args = prepareProductBuildArgs(identity, keychainName);
145 args.push("--distribution", distInfoFile);
146 args.push(artifactPath);
147 (0, _builderUtil().use)(options.productbuild, it => args.push(...it));
148 yield (0, _builderUtil().exec)("productbuild", args, {
149 cwd: appOutDir
150 });
151 yield Promise.all([(0, _fsExtraP().unlink)(innerPackageFile), (0, _fsExtraP().unlink)(distInfoFile)]);
152 packager.dispatchArtifactCreated(artifactPath, _this, arch, packager.computeSafeArtifactName(artifactName, "pkg", arch));
153 })();
154 }
155
156 customizeDistributionConfiguration(distInfoFile, appPath) {
157 var _this2 = this;
158
159 return (0, _bluebirdLst().coroutine)(function* () {
160 yield (0, _builderUtil().exec)("productbuild", ["--synthesize", "--component", appPath, distInfoFile], {
161 cwd: _this2.outDir
162 });
163 const options = _this2.options;
164 let distInfo = yield (0, _fsExtraP().readFile)(distInfoFile, "utf-8");
165 const insertIndex = distInfo.lastIndexOf("</installer-gui-script>");
166 distInfo = distInfo.substring(0, insertIndex) + ` <domains enable_anywhere="${options.allowAnywhere}" enable_currentUserHome="${options.allowCurrentUserHome}" enable_localSystem="${options.allowRootDirectory}" />\n` + distInfo.substring(insertIndex);
167 const license = yield (0, _license().getNotLocalizedLicenseFile)(options.license, _this2.packager);
168
169 if (license != null) {
170 distInfo = distInfo.substring(0, insertIndex) + ` <license file="${license}"/>\n` + distInfo.substring(insertIndex);
171 }
172
173 (0, _builderUtil().debug)(distInfo);
174 yield (0, _fsExtraP().writeFile)(distInfoFile, distInfo);
175 })();
176 }
177
178 buildComponentPackage(appPath, propertyListOutputFile, packageOutputFile) {
179 var _this3 = this;
180
181 return (0, _bluebirdLst().coroutine)(function* () {
182 const options = _this3.options;
183 const rootPath = path.dirname(appPath); // first produce a component plist template
184
185 yield (0, _builderUtil().exec)("pkgbuild", ["--analyze", "--root", rootPath, propertyListOutputFile]); // process the template plist
186
187 const plistInfo = (0, _plist().parse)((yield (0, _fsExtraP().readFile)(propertyListOutputFile, "utf8")));
188
189 if (plistInfo.length > 0) {
190 const packageInfo = plistInfo[0]; // ChildBundles lists all of electron binaries within the .app.
191 // There is no particular reason for removing that key, except to be as close as possible to
192 // the PackageInfo generated by previous versions of electron-builder.
193
194 delete packageInfo.ChildBundles;
195
196 if (options.isRelocatable != null) {
197 packageInfo.BundleIsRelocatable = options.isRelocatable;
198 }
199
200 if (options.isVersionChecked != null) {
201 packageInfo.BundleIsVersionChecked = options.isVersionChecked;
202 }
203
204 if (options.hasStrictIdentifier != null) {
205 packageInfo.BundleHasStrictIdentifier = options.hasStrictIdentifier;
206 }
207
208 if (options.overwriteAction != null) {
209 packageInfo.BundleOverwriteAction = options.overwriteAction;
210 }
211
212 yield (0, _fsExtraP().writeFile)(propertyListOutputFile, (0, _plist().build)(plistInfo));
213 } // now build the package
214
215
216 const args = ["--root", rootPath, "--component-plist", propertyListOutputFile];
217 (0, _builderUtil().use)(_this3.options.installLocation || "/Applications", it => args.push("--install-location", it));
218
219 if (options.scripts != null) {
220 args.push("--scripts", path.resolve(_this3.packager.info.buildResourcesDir, options.scripts));
221 } else if (options.scripts !== null) {
222 const dir = path.join(_this3.packager.info.buildResourcesDir, "pkg-scripts");
223 const stat = yield (0, _fs().statOrNull)(dir);
224
225 if (stat != null && stat.isDirectory()) {
226 args.push("--scripts", dir);
227 }
228 }
229
230 args.push(packageOutputFile);
231 yield (0, _builderUtil().exec)("pkgbuild", args);
232 })();
233 }
234
235}
236
237exports.PkgTarget = PkgTarget;
238
239function prepareProductBuildArgs(identity, keychain) {
240 const args = [];
241
242 if (identity != null) {
243 args.push("--sign", identity.hash);
244
245 if (keychain != null) {
246 args.push("--keychain", keychain);
247 }
248 }
249
250 return args;
251}
252//# sourceMappingURL=pkg.js.map
\No newline at end of file