From 45ace6cf5f004027d82d6ee2ab12b1b1266ebc2a Mon Sep 17 00:00:00 2001 From: Mark Lee Date: Tue, 30 Jan 2018 14:38:10 -0800 Subject: [PATCH] feat(publisher): add dir to publisher args & convert args from positional to keyword BREAKING CHANGE: Arguments for publisher modules have changed from positional to keyword --- README.md | 19 +++++---- src/api/publish.js | 11 ++++- src/publishers/electron-release-server.js | 2 +- src/publishers/github.js | 2 +- src/publishers/s3.js | 2 +- test/fast/publish_spec.js | 51 +++++++++++------------ 6 files changed, 48 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index c648856abe..5d85d5d3f8 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/api/publish.js b/src/api/publish.js index 877ad789e8..04d8f09587 100644 --- a/src/api/publish.js +++ b/src/api/publish.js @@ -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, + }); } }; diff --git a/src/publishers/electron-release-server.js b/src/publishers/electron-release-server.js index 4395afa2a6..8bc693d8dc 100644 --- a/src/publishers/electron-release-server.js +++ b/src/publishers/electron-release-server.js @@ -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 diff --git a/src/publishers/github.js b/src/publishers/github.js index 4c276e3dd7..51b1522e79 100644 --- a/src/publishers/github.js +++ b/src/publishers/github.js @@ -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 diff --git a/src/publishers/s3.js b/src/publishers/s3.js index 46d2ee06d2..1e9349acb8 100644 --- a/src/publishers/s3.js +++ b/src/publishers/s3.js @@ -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; diff --git a/test/fast/publish_spec.js b/test/fast/publish_spec.js index eeda9a0793..503c6a7a38 100644 --- a/test/fast/publish_spec.js +++ b/test/fast/publish_spec.js @@ -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'); }); });