Skip to content

Commit

Permalink
feat(snap): custom plugs
Browse files Browse the repository at this point in the history
Close #1226
  • Loading branch information
develar committed Feb 9, 2017
1 parent 7cae06a commit 3aed0b5
Show file tree
Hide file tree
Showing 7 changed files with 278 additions and 24 deletions.
5 changes: 3 additions & 2 deletions docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ See [NSIS target notes](https://github.com/electron-userland/electron-builder/wi
### `pkg` macOS Product Archive Options
| Name | Description
| --- | ---
| scripts | <a name="PkgOptions-scripts"></a><p>The scripts directory, relative to <code>build</code> (build resources directory). Defaults to <code>build/pkg-scripts</code>. [Scripting in installer packages](http://macinstallers.blogspot.de/2012/07/scripting-in-installer-packages.html) The scripts can be in any language so long as the files are marked executable and have the appropriate shebang indicating the path to the interpreter.</p> <p>Scripts are required to be executable (<code>chmod +x file</code>). It is not checked and corrected by electron-builder.</p>
| scripts | <a name="PkgOptions-scripts"></a><p>The scripts directory, relative to <code>build</code> (build resources directory). Defaults to <code>build/pkg-scripts</code>. See [Scripting in installer packages](http://macinstallers.blogspot.de/2012/07/scripting-in-installer-packages.html). The scripts can be in any language so long as the files are marked executable and have the appropriate shebang indicating the path to the interpreter.</p> <p>Scripts are required to be executable (<code>chmod +x file</code>).</p>
| installLocation | <a name="PkgOptions-installLocation"></a>The install location. Defaults to `/Applications`.

<a name="Protocol"></a>
Expand Down Expand Up @@ -246,7 +246,8 @@ To use Squirrel.Windows please install `electron-builder-squirrel-windows` depen
| summary | <a name="SnapOptions-summary"></a>The 78 character long summary. Defaults to [productName](#AppMetadata-productName).
| grade | <a name="SnapOptions-grade"></a><p>The quality grade of the snap. It can be either <code>devel</code> (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). Defaults to <code>stable</code>.</p>
| assumes | <a name="SnapOptions-assumes"></a>The list of features that must be supported by the core in order for this snap to install.
| stagePackages | <a name="SnapOptions-stagePackages"></a><p>The list of Ubuntu packages to use that are needed to support the <code>app</code> part creation. Like <code>depends</code> for <code>deb</code>. Defaults to <code>[&quot;libnotify4&quot;, &quot;libappindicator1&quot;, &quot;libxtst6&quot;, &quot;libnss3&quot;, &quot;libxss1&quot;, &quot;fontconfig-config&quot;, &quot;gconf2&quot;, &quot;libasound2&quot;]</code>.</p>
| stagePackages | <a name="SnapOptions-stagePackages"></a><p>The list of Ubuntu packages to use that are needed to support the <code>app</code> part creation. Like <code>depends</code> for <code>deb</code>. Defaults to <code>[&quot;libnotify4&quot;, &quot;libappindicator1&quot;, &quot;libxtst6&quot;, &quot;libnss3&quot;, &quot;libxss1&quot;, &quot;fontconfig-config&quot;, &quot;gconf2&quot;, &quot;libasound2&quot;, &quot;pulseaudio&quot;]</code>.</p> <p>If list contains <code>default</code>, it will be replaced to default list, so, <code>[&quot;default&quot;, &quot;foo&quot;]</code> can be used to add custom package <code>foo</code> in addition to defaults.</p>
| plugs | <a name="SnapOptions-plugs"></a><p>The list of [plugs](https://snapcraft.io/docs/reference/interfaces). Defaults to <code>[&quot;home&quot;, &quot;x11&quot;, &quot;unity7&quot;, &quot;browser-support&quot;, &quot;network&quot;, &quot;gsettings&quot;, &quot;pulseaudio&quot;, &quot;opengl&quot;]</code>.</p> <p>If list contains <code>default</code>, it will be replaced to default list, so, <code>[&quot;default&quot;, &quot;foo&quot;]</code> can be used to add custom plug <code>foo</code> in addition to defaults.</p>
| ubuntuAppPlatformContent | <a name="SnapOptions-ubuntuAppPlatformContent"></a><p>Specify <code>ubuntu-app-platform1</code> to use [ubuntu-app-platform](https://insights.ubuntu.com/2016/11/17/how-to-create-snap-packages-on-qt-applications/). Snap size will be greatly reduced, but it is not recommended for now because “the snaps must be connected before running uitk-gallery for the first time”.</p>

<a name="AppImageOptions"></a>
Expand Down
26 changes: 18 additions & 8 deletions packages/electron-builder/src/options/linuxOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,35 +93,45 @@ export interface SnapOptions extends LinuxBuildOptions {
/*
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). Defaults to `strict`.
*/
confinement?: "devmode" | "strict" | null
readonly confinement?: "devmode" | "strict" | null

/*
The 78 character long summary. Defaults to [productName](#AppMetadata-productName).
*/
summary?: string | null
readonly summary?: string | null

/*
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).
Defaults to `stable`.
*/
grade?: "devel" | "stable" | null
readonly grade?: "devel" | "stable" | null

/*
The list of features that must be supported by the core in order for this snap to install.
*/
assumes?: Array<string> | null
readonly assumes?: Array<string> | null

/*
The list of Ubuntu packages to use that are needed to support the `app` part creation. Like `depends` for `deb`.
Defaults to `["libnotify4", "libappindicator1", "libxtst6", "libnss3", "libxss1", "fontconfig-config", "gconf2", "libasound2"]`.
Defaults to `["libnotify4", "libappindicator1", "libxtst6", "libnss3", "libxss1", "fontconfig-config", "gconf2", "libasound2", "pulseaudio"]`.
If list contains `default`, it will be replaced to default list, so, `["default", "foo"]` can be used to add custom package `foo` in addition to defaults.
*/
readonly stagePackages?: Array<string> | null

/*
The list of [plugs](https://snapcraft.io/docs/reference/interfaces).
Defaults to `["home", "x11", "unity7", "browser-support", "network", "gsettings", "pulseaudio", "opengl"]`.
If list contains `default`, it will be replaced to default list, so, `["default", "foo"]` can be used to add custom plug `foo` in addition to defaults.
*/
stagePackages?: Array<string> | null
readonly plugs?: Array<string> | null

/*
Specify `ubuntu-app-platform1` to use [ubuntu-app-platform](https://insights.ubuntu.com/2016/11/17/how-to-create-snap-packages-on-qt-applications/).
Snap size will be greatly reduced, but it is not recommended for now because "the snaps must be connected before running uitk-gallery for the first time".
*/
ubuntuAppPlatformContent?: string | null
readonly ubuntuAppPlatformContent?: string | null
}

/*
Expand All @@ -131,5 +141,5 @@ export interface AppImageOptions extends LinuxBuildOptions {
/*
Whether to include required system libraries (`gconf2`, `libappindicator1`). Defaults to `false`.
*/
includeRequiredLib?: boolean | null
readonly includeRequiredLib?: boolean | null
}
5 changes: 3 additions & 2 deletions packages/electron-builder/src/options/macOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ export interface MacOptions extends PlatformSpecificBuildOptions {
*/
export interface PkgOptions {
/*
The scripts directory, relative to `build` (build resources directory). Defaults to `build/pkg-scripts`. [Scripting in installer packages](http://macinstallers.blogspot.de/2012/07/scripting-in-installer-packages.html)
The scripts directory, relative to `build` (build resources directory). Defaults to `build/pkg-scripts`.
See [Scripting in installer packages](http://macinstallers.blogspot.de/2012/07/scripting-in-installer-packages.html).
The scripts can be in any language so long as the files are marked executable and have the appropriate shebang indicating the path to the interpreter.
Scripts are required to be executable (`chmod +x file`). It is not checked and corrected by electron-builder.
Scripts are required to be executable (`chmod +x file`).
*/
readonly scripts?: string | null

Expand Down
29 changes: 25 additions & 4 deletions packages/electron-builder/src/targets/snap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ export default class SnapTarget extends Target {
snap.apps = {
[snap.name]: {
command: `desktop-launch $SNAP/${packager.executableName}`,
plugs: [
"home", "x11", "unity7", "browser-support", "network", "gsettings", "pulseaudio", "opengl",
]
plugs: [replaceDefault(options.plugs, ["home", "x11", "unity7", "browser-support", "network", "gsettings", "pulseaudio", "opengl"])]
}
}

Expand All @@ -81,10 +79,12 @@ export default class SnapTarget extends Target {

// libxss1, libasound2, gconf2 - was "error while loading shared libraries: libXss.so.1" on Xubuntu 16.04
const isUseDocker = process.platform !== "linux"

const defaultStagePackages = (isUseUbuntuPlatform ? ["libnss3"] : ["libnotify4", "libappindicator1", "libxtst6", "libnss3", "libxss1", "fontconfig-config", "gconf2", "libasound2", "pulseaudio"])
snap.parts = {
app: {
plugin: "dump",
"stage-packages": options.stagePackages || (isUseUbuntuPlatform ? ["libnss3"] : ["libnotify4", "libappindicator1", "libxtst6", "libnss3", "libxss1", "fontconfig-config", "gconf2", "libasound2"]),
"stage-packages": replaceDefault(options.stagePackages, defaultStagePackages),
source: isUseDocker ? `/out/${path.basename(appOutDir)}` : appOutDir,
after: isUseUbuntuPlatform ? ["extra", "desktop-ubuntu-app-platform"] : ["desktop-glib-only"]
}
Expand All @@ -97,6 +97,10 @@ export default class SnapTarget extends Target {
}
}

if (packager.packagerOptions.effectiveOptionComputed != null && await packager.packagerOptions.effectiveOptionComputed(snap)) {
return
}

const snapcraft = path.join(snapDir, "snapcraft.yaml")
await writeFile(snapcraft, safeDump(snap, {lineWidth: 160}))

Expand All @@ -123,4 +127,21 @@ export default class SnapTarget extends Target {
}
packager.dispatchArtifactCreated(resultFile, this)
}
}

function replaceDefault(inList: Array<string> | n, defaultList: Array<string>): Array<string> {
if (inList == null) {
return defaultList
}

const index = inList.indexOf("default")
if (index >= 0) {
let list = inList.slice(0, index)
list.push(...defaultList)
if (index != (inList.length - 1)) {
list.push(...inList.slice(index + 1))
}
inList = list
}
return inList
}
8 changes: 2 additions & 6 deletions packages/electron-publisher-s3/src/s3Publisher.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Publisher, PublishContext } from "electron-builder-publisher"
import { S3Options } from "electron-builder-http/out/publishOptions"
import { S3 } from "aws-sdk"
import { createReadStream, stat } from "fs-extra-p"
import { stat } from "fs-extra-p"
import mime from "mime"
import BluebirdPromise from "bluebird-lst-c"
import { debug, isEmptyOrSpaces } from "electron-builder-util"
Expand Down Expand Up @@ -30,13 +30,9 @@ export default class S3Publisher extends Publisher {
const fileName = basename(file)
const fileStat = await stat(file)
return this.context.cancellationToken.trackPromise(new BluebirdPromise((resolve, reject, onCancel) => {
//noinspection JSUnusedLocalSymbols
const fileStream = createReadStream(file)
fileStream.on("error", reject)

const upload = this.s3.upload({
Bucket: this.info.bucket!,
Key: fileName,
Key: (this.info.path == null ? "" : `${this.info.path}/`) + fileName,
ACL: this.info.acl || "public-read",
Body: this.createReadStreamAndProgressBar(file, fileStat, this.createProgressBar(fileName, fileStat), reject),
ContentLength: fileStat.size,
Expand Down
203 changes: 203 additions & 0 deletions test/out/linux/__snapshots__/snapTest.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
exports[`test default stagePackages 1`] = `
Object {
"apps": Object {
"sep": Object {
"command": "desktop-launch $SNAP/sep",
"plugs": Array [
Array [
"home",
"x11",
"unity7",
"browser-support",
"network",
"gsettings",
"pulseaudio",
"opengl",
],
],
},
},
"confinement": "strict",
"description": "Test Application (test quite “ #378)",
"grade": "stable",
"icon": "setup/gui/icon.png",
"name": "sep",
"parts": Object {
"app": Object {
"after": Array [
"desktop-glib-only",
],
"plugin": "dump",
"source": "/out/linux-unpacked",
"stage-packages": Array [
"libnotify4",
"libappindicator1",
"libxtst6",
"libnss3",
"libxss1",
"fontconfig-config",
"gconf2",
"libasound2",
"pulseaudio",
],
},
},
"summary": "Sep",
"version": "1.1.0",
}
`;

exports[`test default stagePackages 2`] = `
Object {
"apps": Object {
"sep": Object {
"command": "desktop-launch $SNAP/sep",
"plugs": Array [
Array [
"home",
"x11",
"unity7",
"browser-support",
"network",
"gsettings",
"pulseaudio",
"opengl",
"custom",
],
],
},
},
"confinement": "strict",
"description": "Test Application (test quite “ #378)",
"grade": "stable",
"icon": "setup/gui/icon.png",
"name": "sep",
"parts": Object {
"app": Object {
"after": Array [
"desktop-glib-only",
],
"plugin": "dump",
"source": "/out/linux-unpacked",
"stage-packages": Array [
"libnotify4",
"libappindicator1",
"libxtst6",
"libnss3",
"libxss1",
"fontconfig-config",
"gconf2",
"libasound2",
"pulseaudio",
"custom",
],
},
},
"summary": "Sep",
"version": "1.1.0",
}
`;

exports[`test default stagePackages 3`] = `
Object {
"apps": Object {
"sep": Object {
"command": "desktop-launch $SNAP/sep",
"plugs": Array [
Array [
"custom",
"home",
"x11",
"unity7",
"browser-support",
"network",
"gsettings",
"pulseaudio",
"opengl",
],
],
},
},
"confinement": "strict",
"description": "Test Application (test quite “ #378)",
"grade": "stable",
"icon": "setup/gui/icon.png",
"name": "sep",
"parts": Object {
"app": Object {
"after": Array [
"desktop-glib-only",
],
"plugin": "dump",
"source": "/out/linux-unpacked",
"stage-packages": Array [
"custom",
"libnotify4",
"libappindicator1",
"libxtst6",
"libnss3",
"libxss1",
"fontconfig-config",
"gconf2",
"libasound2",
"pulseaudio",
],
},
},
"summary": "Sep",
"version": "1.1.0",
}
`;

exports[`test default stagePackages 4`] = `
Object {
"apps": Object {
"sep": Object {
"command": "desktop-launch $SNAP/sep",
"plugs": Array [
Array [
"foo1",
"home",
"x11",
"unity7",
"browser-support",
"network",
"gsettings",
"pulseaudio",
"opengl",
"foo2",
],
],
},
},
"confinement": "strict",
"description": "Test Application (test quite “ #378)",
"grade": "stable",
"icon": "setup/gui/icon.png",
"name": "sep",
"parts": Object {
"app": Object {
"after": Array [
"desktop-glib-only",
],
"plugin": "dump",
"source": "/out/linux-unpacked",
"stage-packages": Array [
"foo1",
"libnotify4",
"libappindicator1",
"libxtst6",
"libnss3",
"libxss1",
"fontconfig-config",
"gconf2",
"libasound2",
"pulseaudio",
"foo2",
],
},
},
"summary": "Sep",
"version": "1.1.0",
}
`;
Loading

0 comments on commit 3aed0b5

Please sign in to comment.