diff --git a/lib/commands/base.js b/lib/commands/base.js index cfe2e94a..6026cd5d 100644 --- a/lib/commands/base.js +++ b/lib/commands/base.js @@ -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'); @@ -14,6 +15,7 @@ module.exports = Command.extend({ Electron: ElectronTask, ElectronMake: ElectronMakeTask, ElectronPackage: ElectronPackageTask, + ElectronPublish: ElectronPublishTask, YarnOrNpm: YarnOrNpmTask, }); }, diff --git a/lib/commands/make.js b/lib/commands/make.js index 33b2ae33..2a0785e7 100644 --- a/lib/commands/make.js +++ b/lib/commands/make.js @@ -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 }); } @@ -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; }, }); diff --git a/lib/tasks/publish.js b/lib/tasks/publish.js new file mode 100644 index 00000000..5f2632d7 --- /dev/null +++ b/lib/tasks/publish.js @@ -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; diff --git a/node-tests/integration/commands/make-test.js b/node-tests/integration/commands/make-test.js index dc8feebe..91de90f4 100644 --- a/node-tests/integration/commands/make-test.js +++ b/node-tests/integration/commands/make-test.js @@ -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'); @@ -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(), @@ -32,6 +34,7 @@ describe('electron:make command', function () { tasks: { Build: BuildTask, ElectronMake: MakeTask, + ElectronPublish: PublishTask, }, }); }); @@ -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', + ]); + }); });