Skip to content

Commit

Permalink
feat(maker): add builtin snap support
Browse files Browse the repository at this point in the history
  • Loading branch information
malept committed Feb 1, 2018
1 parent 45ace6c commit 86f987d
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 2 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,16 @@ config object:
"make_targets": {
"win32": ["squirrel"], // An array of win32 make targets
"darwin": ["zip", "dmg"], // An array of darwin make targets
"linux": ["deb", "rpm", "flatpak"] // An array of linux make targets
"linux": ["deb", "rpm", "flatpak", "snap"] // An array of linux make targets
},
"electronPackagerConfig": {},
"electronRebuildConfig": {},
"electronWinstallerConfig": {},
"electronInstallerDMG": {},
"electronInstallerFlatpak": {},
"electronInstallerDebian": {},
"electronInstallerRedhat": {}
"electronInstallerRedhat": {},
"electronInstallerSnap": {}
}
```

Expand All @@ -186,6 +187,7 @@ config object:
| `deb` | Linux | Generates a Debian package | [`electronInstallerDebian`](https://github.com/unindented/electron-installer-debian#options) | Yes | [`fakeroot` and `dpkg`](https://github.com/unindented/electron-installer-debian#requirements) |
| `rpm` | Linux | Generates an RPM package | [`electronInstallerRedhat`](https://github.com/unindented/electron-installer-redhat#options) | Yes | [`rpm`](https://github.com/unindented/electron-installer-redhatn#requirements) |
| `flatpak` | Linux | Generates a [Flatpak](http://flatpak.org/) file | [`electronInstallerFlatpak`](https://github.com/endlessm/electron-installer-flatpak#options) | No | [`flatpak-builder`](https://github.com/endlessm/electron-installer-flatpak#requirements) |
| `snap` | Linux | Generates a [Snap](https://snapcraft.io/) file | [`electronInstallerSnap`](https://github.com/electron-userland/electron-installer-snap/blob/master/docs/api.md#options) | No | [`snapcraft`](https://snapcraft.io/docs/build-snaps/#install-snapcraft) |

## Configuring `package`

Expand Down
1 change: 1 addition & 0 deletions SUPPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ feature. Known modules include:
* `electron-installer-dmg`
* `electron-installer-flatpak`
* `electron-installer-redhat`
* `electron-installer-snap:*`
* `electron-osx-sign`
* `electron-packager`
* `electron-rebuild`
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
"electron-installer-dmg": "^0.2.0",
"electron-installer-flatpak": "^0.8.0",
"electron-installer-redhat": "^0.5.0",
"electron-installer-snap": "^2.0.0",
"electron-windows-store": "^0.12.0",
"electron-winstaller": "^2.5.0",
"electron-wix-msi": "^1.3.0"
Expand Down
22 changes: 22 additions & 0 deletions src/makers/linux/snap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import path from 'path';

import { ensureDirectory } from '../../util/ensure-output';
import configFn from '../../util/config-fn';

export const isSupportedOnCurrentPlatform = async () => process.platform === 'linux';

export default async ({ dir, targetArch, forgeConfig }) => {
const installer = require('electron-installer-snap');

const outPath = path.resolve(dir, '../make');

await ensureDirectory(outPath);
const snapDefaults = {
arch: targetArch,
dest: outPath,
src: dir,
};
const snapConfig = Object.assign({}, configFn(forgeConfig.electronInstallerSnap, targetArch), snapDefaults);

return [await installer(snapConfig)];
};
59 changes: 59 additions & 0 deletions test/fast/makers/snap_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import chai, { expect } from 'chai';
import chaiAsPromised from 'chai-as-promised';
import path from 'path';
import proxyquire from 'proxyquire';
import { stub } from 'sinon';

chai.use(chaiAsPromised);

describe('snap maker', () => {
let snapModule;
let snapMaker;
let eisStub;
let ensureDirectoryStub;
let forgeConfig;

const dir = '/my/test/dir/out/foo-linux-x64';
const appName = 'My Test App';
const targetArch = process.arch;
const packageJSON = { version: '1.2.3' };

beforeEach(() => {
ensureDirectoryStub = stub().returns(Promise.resolve());
eisStub = stub().resolves('/my/test/dir/out/make/foo_0.0.1_amd64.snap');
forgeConfig = { electronInstallerSnap: {} };

snapModule = proxyquire.noPreserveCache().noCallThru().load('../../../src/makers/linux/snap', {
'./config-fn': config => config,
'../../util/ensure-output': { ensureDirectory: ensureDirectoryStub },
'electron-installer-snap': eisStub,
});
snapMaker = snapModule.default;
});

it('should pass through correct defaults', async () => {
await snapMaker({ dir, appName, targetArch, forgeConfig, packageJSON });
const opts = eisStub.firstCall.args[0];
expect(opts).to.deep.equal({
arch: process.arch,
src: dir,
dest: path.resolve(dir, '..', 'make'),
});
});

it('should have config cascade correctly', async () => {
forgeConfig.electronInstallerSnap = {
arch: 'overridden',
description: 'Snap description',
};

await snapMaker({ dir, appName, targetArch, forgeConfig, packageJSON });
const opts = eisStub.firstCall.args[0];
expect(opts).to.deep.equal({
arch: process.arch,
src: dir,
dest: path.resolve(dir, '..', 'make'),
description: 'Snap description',
});
});
});
1 change: 1 addition & 0 deletions test/fast/makers_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe('makers', () => {
'linux/deb': ['darwin', 'linux'],
'linux/flatpak': ['darwin', 'linux'],
'linux/rpm': ['darwin', 'linux'],
'linux/snap': ['linux'],
'win32/appx': ['win32'],
'win32/squirrel': ['darwin', 'linux', 'win32'],
'win32/wix': ['win32'],
Expand Down

0 comments on commit 86f987d

Please sign in to comment.