Skip to content
Permalink
Browse files

feat(publisher): add dir to publisher args & convert args from positi…

…onal to keyword

BREAKING CHANGE:
Arguments for publisher modules have changed from positional to keyword
  • Loading branch information
malept committed Jan 30, 2018
1 parent 8d5ff91 commit 45ace6cf5f004027d82d6ee2ab12b1b1266ebc2a
Showing with 48 additions and 39 deletions.
  1. +10 −9 README.md
  2. +10 −1 src/api/publish.js
  3. +1 −1 src/publishers/electron-release-server.js
  4. +1 −1 src/publishers/github.js
  5. +1 −1 src/publishers/s3.js
  6. +25 −26 test/fast/publish_spec.js
@@ -280,15 +280,16 @@ Your promise must resolve with an array of the artifacts you generated.

### API for `publish` targets

You must export a Function that returns a Promise. Your function will be called with the following parameters.

* artifactPaths - An array of absolute paths to artifacts to publish
* packageJSON - An object representing the users package.json file
* forgeConfig - An object representing the users forgeConfig
* authToken - The value of `--auth-token`
* tag - The value of `--tag`
* platform - The platform you are publishing for
* arch - The arch you are publishing for
You must export a `Function` that returns a `Promise`. Your function will be called with the following keyword parameters:

* `dir` - The application directory
* `artifactPaths` - An array of absolute paths to artifacts to publish
* `packageJSON` - An object representing the user's `package.json` file
* `forgeConfig` - An object representing the user's [`forgeConfig`](#config)
* `authToken` - The value of `--auth-token`
* `tag` - The value of `--tag`
* `platform` - The platform you are publishing for
* `arch` - The arch you are publishing for

You should use `ora` to indicate your publish progress.

@@ -139,7 +139,16 @@ const publish = async (providedOptions = {}) => {
}
});

await publisher(artifacts, packageJSON, forgeConfig, authToken, tag, makeOptions.platform || process.platform, makeOptions.arch || process.arch);
await publisher({
dir,
artifacts,
packageJSON,
forgeConfig,
authToken,
tag,
platform: makeOptions.platform || process.platform,
arch: makeOptions.arch || process.arch,
});
}
};

@@ -21,7 +21,7 @@ const ersPlatform = (platform, arch) => {
}
};

export default async (artifacts, packageJSON, forgeConfig, authToken, tag, platform, arch) => {
export default async ({ artifacts, packageJSON, forgeConfig, platform, arch }) => {
const ersConfig = forgeConfig.electronReleaseServer;
if (!(ersConfig.baseUrl && ersConfig.username && ersConfig.password)) {
throw 'In order to publish to ERS you must set the "electronReleaseServer.baseUrl", "electronReleaseServer.username" and "electronReleaseServer.password" properties in your forge config. See the docs for more info'; // eslint-disable-line
@@ -5,7 +5,7 @@ import path from 'path';
import asyncOra from '../util/ora-handler';
import GitHub from '../util/github';

export default async (artifacts, packageJSON, forgeConfig, authToken, tag) => {
export default async ({ artifacts, packageJSON, forgeConfig, authToken, tag }) => {
if (!(forgeConfig.github_repository && typeof forgeConfig.github_repository === 'object' &&
forgeConfig.github_repository.owner && forgeConfig.github_repository.name)) {
throw 'In order to publish to github you must set the "github_repository.owner" and "github_repository.name" properties in your forge config. See the docs for more info'; // eslint-disable-line
@@ -13,7 +13,7 @@ AWS.util.update(AWS.S3.prototype, {
},
});

export default async (artifacts, packageJSON, forgeConfig, authToken, tag) => {
export default async ({ artifacts, packageJSON, forgeConfig, authToken, tag }) => {
const s3Config = forgeConfig.s3;

s3Config.secretAccessKey = s3Config.secretAccessKey || authToken;
@@ -52,15 +52,16 @@ describe('publish', () => {
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',
process.platform,
process.arch,
]);
expect(publisherSpy.firstCall.args).to.deep.equal([{
dir: resolveStub(),
artifacts: ['artifact1', 'artifact2'],
packageJSON: require('../fixture/dummy_app/package.json'),
forgeConfig: await require('../../src/util/forge-config').default(path.resolve(__dirname, '../fixture/dummy_app')),
authToken: 'my_token',
tag: 'my_special_tag',
platform: process.platform,
arch: process.arch,
}]);
});

it('should default to publishing to github', async () => {
@@ -198,28 +199,26 @@ describe('publish', () => {
it('should successfully restore values and pass them to publisher', () => {
expect(makeStub.callCount).to.equal(0);
expect(publisher.callCount).to.equal(2, 'should call once for each platform (make run)');
const darwinIndex = publisher.firstCall.args[5] === 'darwin' ? 0 : 1;
const darwinIndex = publisher.firstCall.args[0].platform === 'darwin' ? 0 : 1;
const win32Index = darwinIndex === 0 ? 1 : 0;
expect(publisher.getCall(darwinIndex).args[1]).to.deep.equal({ state: 1 });
expect(publisher.getCall(darwinIndex).args.slice(3)).to.deep.equal([
undefined,
null,
'darwin',
'x64',
]);
expect(publisher.getCall(darwinIndex).args[0].sort()).to.deep.equal(
const darwinArgs = publisher.getCall(darwinIndex).args[0];
expect(darwinArgs.artifacts.sort()).to.deep.equal(
fakeMake('darwin').reduce((accum, val) => accum.concat(val.artifacts), []).sort()
);
expect(publisher.getCall(win32Index).args[1]).to.deep.equal({ state: 0 });
expect(publisher.getCall(win32Index).args.slice(3)).to.deep.equal([
undefined,
null,
'win32',
'x64',
]);
expect(publisher.getCall(win32Index).args[0].sort()).to.deep.equal(
expect(darwinArgs.packageJSON).to.deep.equal({ state: 1 });
expect(darwinArgs.authToken).to.equal(undefined);
expect(darwinArgs.tag).to.equal(null);
expect(darwinArgs.platform).to.equal('darwin');
expect(darwinArgs.arch).to.equal('x64');
const win32Args = publisher.getCall(win32Index).args[0];
expect(win32Args.artifacts.sort()).to.deep.equal(
fakeMake('win32').reduce((accum, val) => accum.concat(val.artifacts), []).sort()
);
expect(win32Args.packageJSON).to.deep.equal({ state: 0 });
expect(win32Args.authToken).to.equal(undefined);
expect(win32Args.tag).to.equal(null);
expect(win32Args.platform).to.equal('win32');
expect(win32Args.arch).to.equal('x64');
});
});

0 comments on commit 45ace6c

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