Skip to content

Commit 1bd54f7

Browse files
committed
feat(linux): Build snap packages for Linux #509
1 parent 171ad14 commit 1bd54f7

File tree

19 files changed

+234
-94
lines changed

19 files changed

+234
-94
lines changed

.idea/dictionaries/develar.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/linuxPackagerTest.xml

Lines changed: 0 additions & 14 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ A complete solution to package and build a ready for distribution Electron app f
1010
* Numerous target formats:
1111
* All platforms: `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`, `dir` (unpacked directory).
1212
* [macOS](https://github.com/electron-userland/electron-builder/wiki/Options#MacOptions-target): `dmg`, `pkg`, `mas`.
13-
* [Linux](https://github.com/electron-userland/electron-builder/wiki/Options#LinuxBuildOptions-target): `AppImage`, `deb`, `rpm`, `freebsd`, `pacman`, `p5p`, `apk`.
13+
* [Linux](https://github.com/electron-userland/electron-builder/wiki/Options#LinuxBuildOptions-target): [AppImage](http://appimage.org), [snap](http://snapcraft.io), `deb`, `rpm`, `freebsd`, `pacman`, `p5p`, `apk`.
1414
* [Windows](https://github.com/electron-userland/electron-builder/wiki/Options#WinBuildOptions-target): NSIS, Squirrel.Windows.
1515
* [Two package.json Structure](https://github.com/electron-userland/electron-builder/wiki/Two-package.json-Structure) is supported, but you are not forced to use it even if you have native production dependencies.
1616
* [Publishing artifacts](https://github.com/electron-userland/electron-builder/wiki/Publishing-Artifacts) to GitHub Releases and Bintray.

docker/base/Dockerfile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM buildpack-deps:xenial-curl
1+
FROM buildpack-deps:yakkety-curl
22

33
# rpm is required for FPM to build rpm package
44
# yasm is required to build p7zip
@@ -15,10 +15,9 @@ ENV USE_SYSTEM_7ZA true
1515
ENV DEBUG_COLORS true
1616
ENV FORCE_COLOR true
1717

18-
RUN apt-key adv --keyserver pgp.mit.edu --recv D101F7899D41F3C3 && echo "deb http://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
19-
20-
RUN apt-get update -y && \
21-
apt-get install --no-install-recommends -y yarn xorriso bsdtar build-essential autoconf libssl-dev icnsutils graphicsmagick gcc-multilib g++-multilib libgnome-keyring-dev lzip rpm yasm && \
18+
RUN apt-key adv --keyserver pgp.mit.edu --recv D101F7899D41F3C3 && apt-key adv --fetch-keys http://dl.yarnpkg.com/debian/pubkey.gpg && echo "deb http://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
19+
apt-get update -y && \
20+
apt-get install --no-install-recommends -y git snapcraft yarn xorriso bsdtar build-essential autoconf libssl-dev icnsutils graphicsmagick gcc-multilib g++-multilib libgnome-keyring-dev lzip rpm yasm && \
2221
apt-get clean && \
2322
rm -rf /var/lib/apt/lists/* && \
2423
curl -L http://tukaani.org/xz/xz-$XZ_VERSION.tar.xz | tar -xJ && cd xz-$XZ_VERSION && ./configure && make && make install && cd .. && rm -rf xz-$XZ_VERSION && ldconfig && \

docker/wine/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM electronuserland/electron-builder:latest
22

33
# libgnome-keyring-dev — to build keytar
44
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F9CB8DB0 && \
5-
echo "deb http://ppa.launchpad.net/ubuntu-wine/ppa/ubuntu xenial main " | tee /etc/apt/sources.list.d/wine.list && \
5+
echo "deb http://ppa.launchpad.net/ubuntu-wine/ppa/ubuntu yakkety main " | tee /etc/apt/sources.list.d/wine.list && \
66
dpkg --add-architecture i386 && \
77
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF && \
88
echo "deb http://download.mono-project.com/repo/debian wheezy main" | tee /etc/apt/sources.list.d/mono-xamarin.list && \

docs/Options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ Linux specific build options.
142142
| category | <a name="LinuxBuildOptions-category"></a>The [application category](https://specifications.freedesktop.org/menu-spec/latest/apa.html#main-category-registry).
143143
| packageCategory | <a name="LinuxBuildOptions-packageCategory"></a>The [package category](https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Section). Not applicable for AppImage.
144144
| description | <a name="LinuxBuildOptions-description"></a>As [description](#AppMetadata-description) from application package.json, but allows you to specify different for Linux.
145-
| target | <a name="LinuxBuildOptions-target"></a><p>Target package type: list of <code>AppImage</code>, <code>deb</code>, <code>rpm</code>, <code>freebsd</code>, <code>pacman</code>, <code>p5p</code>, <code>apk</code>, <code>7z</code>, <code>zip</code>, <code>tar.xz</code>, <code>tar.lz</code>, <code>tar.gz</code>, <code>tar.bz2</code>, <code>dir</code>. Defaults to <code>AppImage</code>.</p> <p>The most effective [xz](https://en.wikipedia.org/wiki/Xz) compression format used by default.</p> <p>Only <code>deb</code> and <code>AppImage</code> is tested. Feel free to file issues for <code>rpm</code> and other package formats.</p>
145+
| target | <a name="LinuxBuildOptions-target"></a><p>Target package type: list of <code>AppImage</code>, <code>snap</code>, <code>deb</code>, <code>rpm</code>, <code>freebsd</code>, <code>pacman</code>, <code>p5p</code>, <code>apk</code>, <code>7z</code>, <code>zip</code>, <code>tar.xz</code>, <code>tar.lz</code>, <code>tar.gz</code>, <code>tar.bz2</code>, <code>dir</code>. Defaults to <code>AppImage</code>.</p> <p>The most effective [xz](https://en.wikipedia.org/wiki/Xz) compression format used by default.</p>
146146
| synopsis | <a name="LinuxBuildOptions-synopsis"></a>*deb-only.* The [short description](https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Description).
147147
| maintainer | <a name="LinuxBuildOptions-maintainer"></a>The maintainer. Defaults to [author](#AppMetadata-author).
148148
| vendor | <a name="LinuxBuildOptions-vendor"></a>The vendor. Defaults to [author](#AppMetadata-author).

package.json

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"lint": "node ./test/lint.js",
2020
"pretest": "yarn run compile && yarn run lint",
2121
"check-deps": "node ./test/out/helpers/checkDeps.js",
22-
"test": "node ./test/out/helpers/runTests.js",
22+
"test": "node --trace-warnings ./test/out/helpers/runTests.js",
2323
"test-linux": "docker run --rm -ti -v ${PWD}:/project -v ${PWD##*/}-node-modules:/project/node_modules -v ~/.electron:/root/.electron electronuserland/electron-builder:wine /test.sh",
2424
"pack-updater": "cd nsis-auto-updater && yarn --production && cd ..",
2525
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
@@ -68,7 +68,7 @@
6868
"cli-cursor": "^1.0.2",
6969
"cuint": "^0.2.2",
7070
"debug": "^2.3.2",
71-
"electron-download": "2.1.2",
71+
"electron-download-tf": "3.1.0",
7272
"electron-macos-sign": "1.0.1",
7373
"fs-extra-p": "^2.0.7",
7474
"hosted-git-info": "^2.1.5",
@@ -143,13 +143,6 @@
143143
]
144144
]
145145
},
146-
"ava": {
147-
"verbose": true,
148-
"cache": false,
149-
"files": [
150-
"test/out/*.js"
151-
]
152-
},
153146
"jest": {
154147
"testEnvironment": "node",
155148
"testPathDirs": [
@@ -167,5 +160,8 @@
167160
"release": {
168161
"verifyConditions": []
169162
},
170-
"typings": "./out/electron-builder.d.ts"
163+
"typings": "./out/electron-builder.d.ts",
164+
"publishConfig": {
165+
"tag": "next"
166+
}
171167
}

src/linuxPackager.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import AppImageTarget from "./targets/appImage"
99
import { rename } from "fs-extra-p"
1010
import { LinuxBuildOptions } from "./options/linuxOptions"
1111
import sanitizeFileName from "sanitize-filename"
12+
import SnapTarget from "./targets/snap"
1213

1314
export class LinuxPackager extends PlatformPackager<LinuxBuildOptions> {
1415
readonly executableName: string
@@ -49,6 +50,10 @@ export class LinuxPackager extends PlatformPackager<LinuxBuildOptions> {
4950
const targetClass: typeof AppImageTarget = require("./targets/appImage").default
5051
mapper("appimage", outDir => new targetClass(this, getHelper(), outDir))
5152
}
53+
else if (name === "snap") {
54+
const targetClass: typeof SnapTarget = require("./targets/snap").default
55+
mapper("snap", outDir => new targetClass(this, getHelper(), outDir))
56+
}
5257
else if (name === "deb" || name === "rpm" || name === "sh" || name === "freebsd" || name === "pacman" || name === "apk" || name === "p5p") {
5358
const targetClass: typeof FpmTarget = require("./targets/fpm").default
5459
mapper(name, outDir => new targetClass(name, this, getHelper(), outDir))

src/options/linuxOptions.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ export interface LinuxBuildOptions extends PlatformSpecificBuildOptions {
2222
readonly description?: string | null
2323

2424
/*
25-
Target package type: list of `AppImage`, `deb`, `rpm`, `freebsd`, `pacman`, `p5p`, `apk`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`, `dir`. Defaults to `AppImage`.
25+
Target package type: list of `AppImage`, `snap`, `deb`, `rpm`, `freebsd`, `pacman`, `p5p`, `apk`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`, `dir`. Defaults to `AppImage`.
2626
2727
The most effective [xz](https://en.wikipedia.org/wiki/Xz) compression format used by default.
28-
29-
Only `deb` and `AppImage` is tested. Feel free to file issues for `rpm` and other package formats.
3028
*/
3129
readonly target?: Array<string> | null
3230

@@ -73,3 +71,26 @@ export interface LinuxBuildOptions extends PlatformSpecificBuildOptions {
7371
*/
7472
readonly executableName?: string | null
7573
}
74+
75+
export interface SnapOptions extends LinuxBuildOptions {
76+
/*
77+
The type of confinement supported by the snap. Can be either `devmode` (i.e. this snap doesn’t support running under confinement) or `strict` (i.e. full confinement supported via interfaces).
78+
*/
79+
confinement?: "devmode" | "strict" | null
80+
81+
/*
82+
The 78 character long summary. Defaults to [productName](#AppMetadata-productName).
83+
*/
84+
summary?: string | null
85+
86+
/*
87+
The quality grade of the snap. It can be either `devel` (i.e. a development version of the snap, so not to be published to the “stable” or “candidate” channels) or “stable” (i.e. a stable release or release candidate, which can be released to all channels).
88+
Defaults to `stable`.
89+
*/
90+
grade?: "devel" | "stable" | null
91+
92+
/*
93+
The list of features that must be supported by the core in order for this snap to install.
94+
*/
95+
assumes?: Array<string> | null
96+
}

src/packager/dirPackager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { debug7zArgs, spawn } from "../util/util"
66
import { path7za } from "7zip-bin"
77
import * as path from "path"
88

9-
const downloadElectron: (options: any) => Promise<any> = BluebirdPromise.promisify(require("electron-download"))
9+
const downloadElectron: (options: any) => Promise<any> = BluebirdPromise.promisify(require("electron-download-tf"))
1010

1111
function createDownloadOpts(opts: any, platform: string, arch: string, electronVersion: string) {
1212
const downloadOpts = Object.assign({

0 commit comments

Comments
 (0)