Skip to content
Permalink
Browse files

feat(publisher): allow platform level config for publish targets

Also allows for multiple publish targets to be run simultaneously

Fixes #118
  • Loading branch information
MarshallOfSound authored and malept committed Feb 4, 2017
1 parent 3fc0a9c commit 8572cad63eab91a5d090970a0133c4800723b5fd
@@ -31,8 +31,11 @@ export default async (providedOptions = {}) => {
interactive: false,
tag: null,
makeOptions: {},
target: 'github',
target: null,
}, providedOptions);
asyncOra.interactive = interactive;
// FIXME(MarshallOfSound): Change the method param to publishTargets in the next major bump
let publishTargets = target;

const makeResults = await make(Object.assign({
dir,
@@ -53,16 +56,25 @@ export default async (providedOptions = {}) => {

const forgeConfig = await getForgeConfig(dir);

let publisher;
await asyncOra(`Resolving publish target: ${`${target}`.cyan}`, async () => {
publisher = requireSearch(__dirname, [
`../publishers/${target}.js`,
`electron-forge-publisher-${target}`,
]);
if (!publisher) {
throw `Could not find a publish target with the name: ${target}`;
}
});
if (publishTargets === null) {
publishTargets = forgeConfig.publish_targets[makeOptions.platform || process.platform];
} else if (typeof publishTargets === 'string') {
// FIXME(MarshallOfSound): Remove this fallback string typeof check in the next major bump
publishTargets = [publishTargets];
}

for (const publishTarget of publishTargets) {
let publisher;
await asyncOra(`Resolving publish target: ${`${publishTarget}`.cyan}`, async () => {
publisher = requireSearch(__dirname, [
`../publishers/${publishTarget}.js`,
`electron-forge-publisher-${publishTarget}`,
]);
if (!publisher) {
throw `Could not find a publish target with the name: ${publishTarget}`;
}
});

await publisher(artifacts, packageJSON, forgeConfig, authToken, tag);
await publisher(artifacts, packageJSON, forgeConfig, authToken, tag);
}
};
@@ -31,7 +31,7 @@ import { getMakeOptions } from './electron-forge-make';
authToken: program.authToken,
tag: program.tag,
};
if (program.target) publishOpts.target = program.target;
if (program.target) publishOpts.target = program.target.split(',');

publishOpts.makeOptions = getMakeOptions();

@@ -18,6 +18,7 @@ export default async (dir) => {
}
forgeConfig = Object.assign({
make_targets: {},
publish_targets: {},
electronPackagerConfig: {},
electronWinstallerConfig: {},
electronInstallerDebian: {},
@@ -30,6 +31,12 @@ export default async (dir) => {
mas: ['zip'],
linux: ['deb', 'rpm'],
}, forgeConfig.make_targets);
forgeConfig.publish_targets = Object.assign({
win32: ['github'],
darwin: ['github'],
mas: ['github'],
linux: ['github'],
}, forgeConfig.publish_targets);

const templateObj = Object.assign({}, packageJSON, { year: (new Date()).getFullYear() });
const template = (obj) => {
@@ -0,0 +1,89 @@
import chai, { expect } from 'chai';
import chaiAsPromised from 'chai-as-promised';
import path from 'path';
import proxyquire from 'proxyquire';
import sinon from 'sinon';

chai.use(chaiAsPromised);

describe('publish', () => {
let publish;
let makeStub;
let requireSearchStub;
let resolveStub;
let publisherSpy;

beforeEach(() => {
requireSearchStub = sinon.stub();
resolveStub = sinon.stub();
makeStub = sinon.stub();
publisherSpy = sinon.stub();

publish = proxyquire.noCallThru().load('../../src/api/publish', {
'./make': async (...args) => makeStub(...args),
'../util/resolve-dir': async dir => resolveStub(dir),
'../util/read-package-json': () => Promise.resolve(require('../fixture/dummy_app/package.json')),
'../util/require-search': requireSearchStub,
}).default;

publisherSpy.returns(Promise.resolve());
requireSearchStub.returns(publisherSpy);
resolveStub.returns(path.resolve(__dirname, '../fixture/dummy_app'));
makeStub.returns([]);
});

it('should should call make with makeOptions', async () => {
await publish({
dir: __dirname,
interactive: false,
});
expect(makeStub.callCount).to.equal(1);
});

it('should call the resolved publisher with the appropriate args', async () => {
makeStub.returns([['artifact1', 'artifact2']]);
await publish({
dir: __dirname,
interactive: false,
authToken: 'my_token',
tag: 'my_special_tag',
});
expect(publisherSpy.callCount).to.equal(1);
expect(publisherSpy.firstCall.args).to.deep.equal([
['artifact1', 'artifact2'],
require('../fixture/dummy_app/package.json'),
await require('../../src/util/forge-config').default(path.resolve(__dirname, '../fixture/dummy_app')),
'my_token',
'my_special_tag',
]);
});

it('should default to publishing to github', async () => {
await publish({
dir: __dirname,
interactive: false,
});
expect(requireSearchStub.firstCall.args[1][0]).to.equal('../publishers/github.js');
});

it('should resolve publishers when given a string name', async () => {
await publish({
dir: __dirname,
interactive: false,
target: 'void',
});
expect(requireSearchStub.firstCall.args[1][0]).to.equal('../publishers/void.js');
});

it('should resolve consecutive publishers when given an array of names', async () => {
await publish({
dir: __dirname,
interactive: false,
target: ['void', 'nowhere', 'black_hole', 'everywhere'],
});
expect(requireSearchStub.getCall(0).args[1][0]).to.equal('../publishers/void.js');
expect(requireSearchStub.getCall(1).args[1][0]).to.equal('../publishers/nowhere.js');
expect(requireSearchStub.getCall(2).args[1][0]).to.equal('../publishers/black_hole.js');
expect(requireSearchStub.getCall(3).args[1][0]).to.equal('../publishers/everywhere.js');
});
});
File renamed without changes.
@@ -21,7 +21,11 @@
"electronInstallerRedhat": {},
"electronInstallerDebian": {},
"electronWinstallerConfig": { "windows": "magic" },
"windowsStoreConfig": { "packageName": "test" }
"windowsStoreConfig": { "packageName": "test" },
"github_repository": {
"owner": "dummy",
"name": "project"
}
}
},
"devDependencies": {

0 comments on commit 8572cad

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