Skip to content
Permalink
Browse files

feat(maker): add builtin snap support

  • Loading branch information
malept committed Sep 26, 2017
1 parent 45ace6c commit 86f987d7acfa7da69856b3d4c02493bc8290dd56
Showing with 88 additions and 2 deletions.
  1. +4 −2 README.md
  2. +1 −0 SUPPORT.md
  3. +1 −0 package.json
  4. +22 −0 src/makers/linux/snap.js
  5. +59 −0 test/fast/makers/snap_spec.js
  6. +1 −0 test/fast/makers_spec.js
@@ -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": {}
}
```

@@ -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`

@@ -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`
@@ -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"
@@ -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)];
};
@@ -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',
});
});
});
@@ -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'],

0 comments on commit 86f987d

Please sign in to comment.
You can’t perform that action at this time.