Skip to content

Commit

Permalink
feat: expose forge publish api (#811)
Browse files Browse the repository at this point in the history
* feat: expose forge publish api

* adds the --publish-targets to make command

* remove console.log

* adds a test for the publish arguments

* default is not required

* modification to not stub publish task
  • Loading branch information
basz authored May 2, 2021
1 parent 26bdc07 commit 14534a7
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/commands/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const Command = require('ember-cli/lib/models/command');
const ElectronTask = require('../tasks/electron');
const ElectronMakeTask = require('../tasks/make');
const ElectronPackageTask = require('../tasks/package');
const ElectronPublishTask = require('../tasks/publish');
const YarnOrNpmTask = require('../tasks/yarn-or-npm');
const prepareRunCommand = require('../utils/prepare-run-command');

Expand All @@ -14,6 +15,7 @@ module.exports = Command.extend({
Electron: ElectronTask,
ElectronMake: ElectronMakeTask,
ElectronPackage: ElectronPackageTask,
ElectronPublish: ElectronPublishTask,
YarnOrNpm: YarnOrNpmTask,
});
},
Expand Down
32 changes: 30 additions & 2 deletions lib/commands/make.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,26 @@ module.exports = BaseCommand.extend({
default: packageOutPath,
aliases: ['o'],
},
{
name: 'publish',
type: Boolean,
default: false,
description: 'Publish packages',
},
{
name: 'publish-targets',
type: String,
default: false,
description:
'Override the publish targets specified in your electron-forge config (separated by comma for mulitple targets)',
},
],

async run(commandOptions) {
await this.prepareRun();

let { environment, skipPackage, skipBuild } = commandOptions;
let { publish, environment, skipPackage, skipBuild } = commandOptions;

if (!skipPackage && !skipBuild) {
await this.runTask('Build', { environment, outputPath: emberBuildPath });
}
Expand All @@ -60,6 +74,20 @@ module.exports = BaseCommand.extend({
commandOptions.targets = commandOptions.targets.split(',');
}

return this.runTask('ElectronMake', commandOptions);
const makeResults = await this.runTask('ElectronMake', commandOptions);

if (publish) {
const publishOptions = { makeResults };

if (commandOptions.publishTargets) {
publishOptions.publishTargets = commandOptions.publishTargets.split(
','
);
}

return this.runTask('ElectronPublish', publishOptions);
}

return makeResults;
},
});
28 changes: 28 additions & 0 deletions lib/tasks/publish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

const chalk = require('chalk');
const Task = require('ember-cli/lib/models/task');
const { electronProjectPath } = require('../utils/build-paths');
const { api } = require('../utils/forge-core');

//
// A task that runs electron-forge publish to publish artifacts.
//
class PublishTask extends Task {
async run(options) {
let { ui } = this;
let { makeResults, publishTargets } = options;

ui.writeLine(chalk.green('Publish Electron project.'));

let publishOptions = {
dir: electronProjectPath,
makeResults,
publishTargets,
};

return await api.publish(publishOptions);
}
}

module.exports = PublishTask;
36 changes: 36 additions & 0 deletions node-tests/integration/commands/make-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { expect } = require('chai');
const BuildTask = require('ember-cli/lib/tasks/build');
const MakeCommand = require('../../../lib/commands/make');
const MakeTask = require('../../../lib/tasks/make');
const PublishTask = require('../../../lib/tasks/publish');
const DependencyChecker = require('ember-cli-dependency-checker/lib/dependency-checker');
const { api } = require('../../../lib/utils/forge-core');
const rimraf = require('rimraf');
Expand All @@ -23,6 +24,7 @@ describe('electron:make command', function () {
beforeEach(function () {
buildTaskStub = sinon.stub(BuildTask.prototype, 'run').resolves();
sinon.stub(api, 'make').resolves();
sinon.stub(api, 'publish').resolves();

command = new MakeCommand({
ui: new MockUI(),
Expand All @@ -32,6 +34,7 @@ describe('electron:make command', function () {
tasks: {
Build: BuildTask,
ElectronMake: MakeTask,
ElectronPublish: PublishTask,
},
});
});
Expand Down Expand Up @@ -157,4 +160,37 @@ describe('electron:make command', function () {
rimraf.sync('electron-app');
await expect(command.validateAndRun([])).to.be.rejected;
});

it('can publish', async function () {
let makeResults = { foo: 'bar' };
api.make.resetBehavior();
api.make.resolves(makeResults);

await expect(command.validateAndRun(['---publish'])).to.be.fulfilled;

expect(api.publish).to.be.calledOnce;
expect(api.publish.firstCall.args[0].dir).to.equal('electron-app');
expect(api.publish.firstCall.args[0].makeResults).to.equal(makeResults);
expect(api.publish.firstCall.args[0].publishTargets).to.be.undefined;
});

it('can publish and set one override publish-target', async function () {
await expect(
command.validateAndRun(['---publish', '--publish-targets=foo'])
).to.be.fulfilled;

expect(api.publish).to.be.calledOnce;
expect(api.publish.firstCall.args[0].publishTargets).to.deep.equal(['foo']);
});

it('can publish and set multiple override publish-targets', async function () {
await expect(
command.validateAndRun(['---publish', '--publish-targets=foo,bar'])
).to.be.fulfilled;
expect(api.publish).to.be.calledOnce;
expect(api.publish.firstCall.args[0].publishTargets).to.deep.equal([
'foo',
'bar',
]);
});
});

0 comments on commit 14534a7

Please sign in to comment.