UNPKG

9.57 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8function _bluebirdLst() {
9 const data = _interopRequireWildcard(require("bluebird-lst"));
10
11 _bluebirdLst = function () {
12 return data;
13 };
14
15 return data;
16}
17
18function _builderUtil() {
19 const data = require("builder-util");
20
21 _builderUtil = function () {
22 return data;
23 };
24
25 return data;
26}
27
28function _builderUtilRuntime() {
29 const data = require("builder-util-runtime");
30
31 _builderUtilRuntime = function () {
32 return data;
33 };
34
35 return data;
36}
37
38function _fs() {
39 const data = require("builder-util/out/fs");
40
41 _fs = function () {
42 return data;
43 };
44
45 return data;
46}
47
48function ejs() {
49 const data = _interopRequireWildcard(require("ejs"));
50
51 ejs = function () {
52 return data;
53 };
54
55 return data;
56}
57
58function _fsExtraP() {
59 const data = require("fs-extra-p");
60
61 _fsExtraP = function () {
62 return data;
63 };
64
65 return data;
66}
67
68function _lazyVal() {
69 const data = require("lazy-val");
70
71 _lazyVal = function () {
72 return data;
73 };
74
75 return data;
76}
77
78var path = _interopRequireWildcard(require("path"));
79
80function _core() {
81 const data = require("../core");
82
83 _core = function () {
84 return data;
85 };
86
87 return data;
88}
89
90function _PublishManager() {
91 const data = require("../publish/PublishManager");
92
93 _PublishManager = function () {
94 return data;
95 };
96
97 return data;
98}
99
100function _license() {
101 const data = require("../util/license");
102
103 _license = function () {
104 return data;
105 };
106
107 return data;
108}
109
110function _pathManager() {
111 const data = require("../util/pathManager");
112
113 _pathManager = function () {
114 return data;
115 };
116
117 return data;
118}
119
120function _targetUtil() {
121 const data = require("./targetUtil");
122
123 _targetUtil = function () {
124 return data;
125 };
126
127 return data;
128}
129
130function _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; } }
131
132const appRunTemplate = new (_lazyVal().Lazy)((0, _bluebirdLst().coroutine)(function* () {
133 return ejs().compile((yield (0, _fsExtraP().readFile)(path.join((0, _pathManager().getTemplatePath)("linux"), "AppRun.sh"), "utf-8")));
134})); // https://unix.stackexchange.com/questions/375191/append-to-sub-directory-inside-squashfs-file
135
136class AppImageTarget extends _core().Target {
137 constructor(ignored, packager, helper, outDir) {
138 super("appImage");
139 this.packager = packager;
140 this.helper = helper;
141 this.outDir = outDir;
142 this.options = Object.assign({}, this.packager.platformSpecificBuildOptions, this.packager.config[this.name]); // we add X-AppImage-BuildId to ensure that new desktop file will be installed
143
144 this.desktopEntry = new (_lazyVal().Lazy)(() => helper.computeDesktopEntry(this.options, "AppRun", {
145 "X-AppImage-Version": `${packager.appInfo.buildVersion}`,
146 "X-AppImage-BuildId": _builderUtilRuntime().UUID.v1()
147 }));
148 }
149
150 build(appOutDir, arch) {
151 var _this = this;
152
153 return (0, _bluebirdLst().coroutine)(function* () {
154 const packager = _this.packager;
155 const options = _this.options; // https://github.com/electron-userland/electron-builder/issues/775
156 // https://github.com/electron-userland/electron-builder/issues/1726
157 // tslint:disable-next-line:no-invalid-template-strings
158
159 const artifactName = packager.expandArtifactNamePattern(options, "AppImage", arch, "${name}-${version}-${arch}.${ext}", false);
160 const artifactPath = path.join(_this.outDir, artifactName);
161
162 _this.logBuilding("AppImage", artifactPath, arch);
163
164 const stageDir = yield (0, _targetUtil().createStageDir)(_this, packager, arch);
165 const resourceName = `appimagekit-${_this.packager.executableName}`;
166 let additionalInstall = yield _this.copyIcons(stageDir.dir, resourceName);
167 additionalInstall += yield _this.copyMimeTypes(stageDir.dir);
168 const license = yield (0, _license().getNotLocalizedLicenseFile)(options.license, _this.packager, ["txt"]);
169
170 if (license != null) {
171 yield (0, _fs().copyOrLinkFile)(license, stageDir.getTempFile("eula.txt"));
172 }
173
174 const finalDesktopFilename = `${_this.packager.executableName}.desktop`;
175 yield Promise.all([(0, _fs().unlinkIfExists)(artifactPath), (0, _fsExtraP().writeFile)(stageDir.getTempFile("/AppRun"), (yield appRunTemplate.value)({
176 systemIntegration: options.systemIntegration || "ask",
177 isShowEula: license != null,
178 desktopFileName: finalDesktopFilename,
179 executableName: _this.packager.executableName,
180 productName: _this.packager.appInfo.productName,
181 resourceName,
182 additionalInstall
183 }), {
184 mode: "0755"
185 }), (0, _fsExtraP().writeFile)(stageDir.getTempFile(finalDesktopFilename), (yield _this.desktopEntry.value))]); // must be after this.helper.icons call
186
187 if (_this.helper.maxIconPath == null) {
188 throw new Error("Icon is not provided");
189 }
190
191 if (_this.packager.packagerOptions.effectiveOptionComputed != null && (yield _this.packager.packagerOptions.effectiveOptionComputed({
192 desktop: yield _this.desktopEntry.value
193 }))) {
194 return;
195 }
196
197 const publishConfig = yield (0, _PublishManager().getAppUpdatePublishConfiguration)(packager, arch, false
198 /* in any case validation will be done on publish */
199 );
200
201 if (publishConfig != null) {
202 yield (0, _fsExtraP().outputFile)(path.join(packager.getResourcesDir(stageDir.dir), "app-update.yml"), (0, _builderUtil().serializeToYaml)(publishConfig));
203 }
204
205 const args = ["appimage", "--stage", stageDir.dir, "--arch", _builderUtil().Arch[arch], "--output", artifactPath, "--app", appOutDir];
206
207 if (packager.compression === "maximum") {
208 args.push("--compression", "xz");
209 }
210
211 packager.info.dispatchArtifactCreated({
212 file: artifactPath,
213 safeArtifactName: packager.computeSafeArtifactName(artifactName, "AppImage", arch, false),
214 target: _this,
215 arch,
216 packager,
217 isWriteUpdateInfo: true,
218 updateInfo: JSON.parse((yield (0, _builderUtil().executeAppBuilder)(args)))
219 });
220 })();
221 }
222
223 copyIcons(stageDir, resourceName) {
224 var _this2 = this;
225
226 return (0, _bluebirdLst().coroutine)(function* () {
227 const iconDirRelativePath = "usr/share/icons/hicolor";
228 const iconDir = path.join(stageDir, iconDirRelativePath);
229 yield (0, _fsExtraP().ensureDir)(iconDir); // https://github.com/AppImage/AppImageKit/issues/438#issuecomment-319094239
230 // expects icons in the /usr/share/icons/hicolor
231
232 const iconNames = yield _bluebirdLst().default.map(_this2.helper.icons, (() => {
233 var _ref2 = (0, _bluebirdLst().coroutine)(function* (icon) {
234 const filename = `${_this2.packager.executableName}.png`;
235 const iconSizeDir = `${icon.size}x${icon.size}/apps`;
236 const dir = path.join(iconDir, iconSizeDir);
237 yield (0, _fsExtraP().ensureDir)(dir);
238 const finalIconFile = path.join(dir, filename);
239 yield (0, _fs().copyOrLinkFile)(icon.file, finalIconFile, null, true);
240
241 if (icon.file === _this2.helper.maxIconPath) {
242 yield (0, _fsExtraP().symlink)(path.relative(stageDir, finalIconFile), path.join(stageDir, filename));
243 }
244
245 return {
246 filename,
247 iconSizeDir,
248 size: icon.size
249 };
250 });
251
252 return function (_x) {
253 return _ref2.apply(this, arguments);
254 };
255 })());
256 let installIcons = "";
257
258 for (const icon of iconNames) {
259 installIcons += `xdg-icon-resource install --noupdate --context apps --size ${icon.size} "$APPDIR/${iconDirRelativePath}/${icon.iconSizeDir}/${icon.filename}" "${resourceName}"\n`;
260 }
261
262 return installIcons;
263 })();
264 }
265
266 copyMimeTypes(stageDir) {
267 var _this3 = this;
268
269 return (0, _bluebirdLst().coroutine)(function* () {
270 let mimeTypes = "";
271
272 for (const fileAssociation of _this3.packager.fileAssociations) {
273 if (fileAssociation.mimeType != null) {
274 mimeTypes += `<mime-type type="${fileAssociation.mimeType}">\n
275 <comment>${_this3.packager.appInfo.productFilename} document</comment>\n
276 <glob pattern="*.${fileAssociation.ext}"/>\n
277 <generic-icon name="x-office-document"/>\n
278 </mime-type>\n`;
279 }
280 } // if no mime-types specified, return
281
282
283 if (mimeTypes === "") {
284 return "";
285 }
286
287 const relativePath = "usr/share/mime";
288 const mimeTypeDir = path.join(stageDir, relativePath);
289 const fileName = `${_this3.packager.executableName}.xml`;
290 const mimeTypeFile = path.join(mimeTypeDir, fileName);
291 yield (0, _fsExtraP().ensureDir)(mimeTypeDir);
292 yield (0, _fsExtraP().writeFile)(mimeTypeFile, `<?xml version="1.0"?>
293<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
294 ${mimeTypes}
295</mime-info>`); // noinspection SpellCheckingInspection
296
297 return `xdg-mime install $SYSTEM_WIDE --novendor "$APPDIR/${relativePath}/${fileName}"\n`;
298 })();
299 }
300
301} exports.default = AppImageTarget;
302//# sourceMappingURL=AppImageTarget.js.map
\No newline at end of file