1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 |
|
8 | function _bluebirdLst() {
|
9 | const data = 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 _builderUtilRuntime() {
|
29 | const data = require("builder-util-runtime");
|
30 |
|
31 | _builderUtilRuntime = 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 semver() {
|
51 | const data = _interopRequireWildcard(require("semver"));
|
52 |
|
53 | semver = function () {
|
54 | return data;
|
55 | };
|
56 |
|
57 | return data;
|
58 | }
|
59 |
|
60 | function _core() {
|
61 | const data = require("../core");
|
62 |
|
63 | _core = function () {
|
64 | return data;
|
65 | };
|
66 |
|
67 | return data;
|
68 | }
|
69 |
|
70 | function _linuxPackager() {
|
71 | const data = require("../linuxPackager");
|
72 |
|
73 | _linuxPackager = function () {
|
74 | return data;
|
75 | };
|
76 |
|
77 | return data;
|
78 | }
|
79 |
|
80 | function _targetUtil() {
|
81 | const data = require("./targetUtil");
|
82 |
|
83 | _targetUtil = 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 |
|
93 | const defaultStagePackages = ["libasound2", "libgconf2-4", "libnotify4", "libnspr4", "libnss3", "libpcre3", "libpulse0", "libxss1", "libxtst6", "libappindicator1"];
|
94 | const defaultPlugs = ["desktop", "desktop-legacy", "home", "x11", "unity7", "browser-support", "network", "gsettings", "pulseaudio", "opengl"];
|
95 |
|
96 | class SnapTarget extends _core().Target {
|
97 | constructor(name, packager, helper, outDir) {
|
98 | super(name);
|
99 | this.packager = packager;
|
100 | this.helper = helper;
|
101 | this.outDir = outDir;
|
102 | this.options = Object.assign({}, this.packager.platformSpecificBuildOptions, this.packager.config[this.name]);
|
103 | this.isUseTemplateApp = false;
|
104 | }
|
105 |
|
106 | replaceDefault(inList, defaultList) {
|
107 | const result = (0, _builderUtil().replaceDefault)(inList, defaultList);
|
108 |
|
109 | if (result !== defaultList) {
|
110 | this.isUseTemplateApp = false;
|
111 | }
|
112 |
|
113 | return result;
|
114 | }
|
115 |
|
116 | get isElectron2() {
|
117 | return semver().gte(this.packager.config.electronVersion || "1.8.3", "2.0.0-beta.1");
|
118 | }
|
119 |
|
120 | createDescriptor(arch) {
|
121 | const appInfo = this.packager.appInfo;
|
122 | const snapName = this.packager.executableName.toLowerCase();
|
123 | const options = this.options;
|
124 | const linuxArchName = (0, _linuxPackager().toAppImageOrSnapArch)(arch);
|
125 | const plugs = normalizePlugConfiguration(options.plugs);
|
126 | const plugNames = this.replaceDefault(plugs == null ? null : Object.getOwnPropertyNames(plugs), defaultPlugs);
|
127 | const desktopPart = this.isElectron2 ? "desktop-gtk3" : "desktop-gtk2";
|
128 | const buildPackages = (0, _builderUtilRuntime().asArray)(options.buildPackages);
|
129 | this.isUseTemplateApp = this.options.useTemplateApp !== false && arch === _builderUtil().Arch.x64 && buildPackages.length === 0 && this.isElectron2;
|
130 | const appDescriptor = {
|
131 | command: `command.sh`,
|
132 | environment: Object.assign({
|
133 | TMPDIR: "$XDG_RUNTIME_DIR",
|
134 | PATH: "$SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH",
|
135 | LD_LIBRARY_PATH: ["$SNAP_LIBRARY_PATH", "$SNAP/usr/lib/" + linuxArchName + "-linux-gnu:$SNAP/usr/lib/" + linuxArchName + "-linux-gnu/pulseaudio", "$SNAP/usr/lib/" + linuxArchName + "-linux-gnu/mesa-egl", "$SNAP/lib:$SNAP/usr/lib:$SNAP/lib/" + linuxArchName + "-linux-gnu:$SNAP/usr/lib/" + linuxArchName + "-linux-gnu", "$LD_LIBRARY_PATH:$SNAP/lib:$SNAP/usr/lib", "$SNAP/lib/" + linuxArchName + "-linux-gnu:$SNAP/usr/lib/" + linuxArchName + "-linux-gnu"].join(":")
|
136 | }, options.environment),
|
137 | plugs: plugNames
|
138 | };
|
139 | const snap = {
|
140 | name: snapName,
|
141 | version: appInfo.version,
|
142 | summary: options.summary || appInfo.productName,
|
143 | description: this.helper.getDescription(options),
|
144 | confinement: options.confinement || "strict",
|
145 | grade: options.grade || "stable",
|
146 | architectures: [(0, _builderUtil().toLinuxArchString)(arch)],
|
147 | apps: {
|
148 | [snapName]: appDescriptor
|
149 | },
|
150 | parts: {
|
151 | app: {
|
152 | plugin: "nil",
|
153 | "stage-packages": this.replaceDefault(options.stagePackages, defaultStagePackages),
|
154 | after: this.replaceDefault(options.after, [desktopPart])
|
155 | }
|
156 | }
|
157 | };
|
158 |
|
159 | if (!this.isUseTemplateApp) {
|
160 | appDescriptor.adapter = "none";
|
161 | }
|
162 |
|
163 | if (buildPackages.length > 0) {
|
164 | snap.parts.app["build-packages"] = buildPackages;
|
165 | }
|
166 |
|
167 | if (plugs != null) {
|
168 | for (const plugName of plugNames) {
|
169 | const plugOptions = plugs[plugName];
|
170 |
|
171 | if (plugOptions == null) {
|
172 | continue;
|
173 | }
|
174 |
|
175 | if (snap.plugs == null) {
|
176 | snap.plugs = {};
|
177 | }
|
178 |
|
179 | snap.plugs[plugName] = plugOptions;
|
180 | }
|
181 | }
|
182 |
|
183 | if (options.assumes != null) {
|
184 | snap.assumes = (0, _builderUtilRuntime().asArray)(options.assumes);
|
185 | }
|
186 |
|
187 | if (!this.isUseTemplateApp && snap.parts.app.after.includes(desktopPart)) {
|
188 |
|
189 | const desktopPartOverride = {
|
190 | "override-build": `set -x
|
191 | snapcraftctl build
|
192 | export XDG_DATA_DIRS=$SNAPCRAFT_PART_INSTALL/usr/share
|
193 | update-mime-database $SNAPCRAFT_PART_INSTALL/usr/share/mime
|
194 |
|
195 | for dir in $SNAPCRAFT_PART_INSTALL/usr/share/icons/*/; do
|
196 | if [ -f $dir/index.theme ]; then
|
197 | if which gtk-update-icon-cache-3.0 &> /dev/null; then
|
198 | gtk-update-icon-cache-3.0 -q $dir
|
199 | elif which gtk-update-icon-cache &> /dev/null; then
|
200 | gtk-update-icon-cache -q $dir
|
201 | fi
|
202 | fi
|
203 | done`
|
204 | };
|
205 |
|
206 | if (appDescriptor.plugs.includes("desktop") || appDescriptor.plugs.includes("desktop-legacy")) {
|
207 | desktopPartOverride.stage = ["-./usr/share/fonts/**"];
|
208 | }
|
209 |
|
210 | snap.parts[desktopPart] = desktopPartOverride;
|
211 | }
|
212 |
|
213 | return snap;
|
214 | }
|
215 |
|
216 | build(appOutDir, arch) {
|
217 | var _this = this;
|
218 |
|
219 | return (0, _bluebirdLst().coroutine)(function* () {
|
220 | const packager = _this.packager;
|
221 | const options = _this.options;
|
222 |
|
223 | const artifactName = packager.expandArtifactNamePattern(_this.options, "snap", arch, "${name}_${version}_${arch}.${ext}", false);
|
224 | const artifactPath = path.join(_this.outDir, artifactName);
|
225 |
|
226 | _this.logBuilding("snap", artifactPath, arch);
|
227 |
|
228 | const snap = _this.createDescriptor(arch);
|
229 |
|
230 | if (_this.isUseTemplateApp) {
|
231 | delete snap.parts;
|
232 | }
|
233 |
|
234 | const stageDir = yield (0, _targetUtil().createStageDirPath)(_this, packager, arch);
|
235 |
|
236 | const snapMetaDir = path.join(stageDir, _this.isUseTemplateApp ? "meta" : "snap");
|
237 | const args = ["snap", "--app", appOutDir, "--stage", stageDir, "--arch", (0, _builderUtil().toLinuxArchString)(arch), "--output", artifactPath, "--executable", _this.packager.executableName, "--docker-image", "electronuserland/builder:latest"];
|
238 | yield _this.helper.icons;
|
239 |
|
240 | if (_this.helper.maxIconPath != null) {
|
241 | if (!_this.isUseTemplateApp) {
|
242 | snap.icon = "snap/gui/icon.png";
|
243 | }
|
244 |
|
245 | args.push("--icon", _this.helper.maxIconPath);
|
246 | }
|
247 |
|
248 | const desktopFile = path.join(snapMetaDir, "gui", `${snap.name}.desktop`);
|
249 | yield _this.helper.writeDesktopEntry(_this.options, packager.executableName, desktopFile, {
|
250 |
|
251 | Icon: "${SNAP}/meta/gui/icon.png"
|
252 | });
|
253 |
|
254 | if (packager.packagerOptions.effectiveOptionComputed != null && (yield packager.packagerOptions.effectiveOptionComputed({
|
255 | snap,
|
256 | desktopFile
|
257 | }))) {
|
258 | return;
|
259 | }
|
260 |
|
261 | yield (0, _fsExtraP().outputFile)(path.join(snapMetaDir, _this.isUseTemplateApp ? "snap.yaml" : "snapcraft.yaml"), (0, _builderUtil().serializeToYaml)(snap));
|
262 | const hooksDir = yield packager.getResource(options.hooks, "snap-hooks");
|
263 |
|
264 | if (hooksDir != null) {
|
265 | args.push("--hooks", hooksDir);
|
266 | }
|
267 |
|
268 | if (_this.isUseTemplateApp) {
|
269 | args.push("--template-url", "electron2");
|
270 | }
|
271 |
|
272 | yield (0, _builderUtil().executeAppBuilder)(args);
|
273 | packager.dispatchArtifactCreated(artifactPath, _this, arch, packager.computeSafeArtifactName(artifactName, "snap", arch, false));
|
274 | })();
|
275 | }
|
276 |
|
277 | }
|
278 |
|
279 | exports.default = SnapTarget;
|
280 |
|
281 | function normalizePlugConfiguration(raw) {
|
282 | if (raw == null) {
|
283 | return null;
|
284 | }
|
285 |
|
286 | const result = {};
|
287 |
|
288 | for (const item of Array.isArray(raw) ? raw : [raw]) {
|
289 | if (typeof item === "string") {
|
290 | result[item] = null;
|
291 | } else {
|
292 | Object.assign(result, item);
|
293 | }
|
294 | }
|
295 |
|
296 | return result;
|
297 | }
|
298 |
|
\ | No newline at end of file |