Skip to content

Commit

Permalink
Build available options based on base command for inherited commands
Browse files Browse the repository at this point in the history
The electron:test and electron:build commands are sub-classes of the built-in test and build commands, so let's build our options off of their options rather than just duplicating them all.
  • Loading branch information
bendemboski committed Nov 22, 2019
1 parent f97f80e commit 1445f59
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 42 deletions.
31 changes: 18 additions & 13 deletions lib/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,7 @@ module.exports = BuildCommand.extend({
name: 'electron:build',
description: `Builds your ember app for Electron and installs it in the Electron app.`,

availableOptions: [
{
name: 'environment',
type: String,
default: 'development',
aliases: ['e', { dev: 'development' }, { prod: 'production' }],
description: 'Possible values are "development", "production", and "test".',
},
{ name: 'output-path', type: 'Path', default: emberBuildPath, aliases: ['o'] },
{ name: 'watch', type: Boolean, default: false, aliases: ['w'] },
{ name: 'watcher', type: String },
{ name: 'suppress-sizes', type: Boolean, default: false },
],
availableOptions: buildAvailableOptions(),

run() {
// Tell our addon that we're building for electron, so it should inject
Expand All @@ -29,3 +17,20 @@ module.exports = BuildCommand.extend({
return this._super(...arguments);
}
});

function buildAvailableOptions() {
// We don't whitelist options here since this command maps so directly to the
// base command (just with an extra env variable and different default output
// path)

return BuildCommand.prototype.availableOptions.map((option) => {
// probably doesn't hurt to share un-modified options objects between
// prototypes, but let's do this just to be safe
option = Object.assign({}, option);

if (option.name === 'output-path') {
option.default = emberBuildPath;
}
return option;
});
}
64 changes: 35 additions & 29 deletions lib/commands/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,7 @@ module.exports = TestCommand.extend({
name: 'electron:test',
description: 'Runs your app\'s test suite in Electron.',

availableOptions: [
{
name: 'environment',
type: String,
default: 'test',
aliases: ['e'],
description: 'Possible values are "development", "production", and "test".',
},
{
name: 'config-file',
type: String,
default: 'testem-electron.js',
aliases: ['c', 'cf']
},
{ name: 'server', type: Boolean, default: false, aliases: ['s'] },
{ name: 'filter', type: String, aliases: ['f'], description: 'A string to filter tests to run' },
{ name: 'module', type: String, aliases: ['m'], description: 'The name of a test module to run' },
{ name: 'watcher', type: String, default: 'events', aliases: ['w'] },
{
name: 'reporter',
type: String,
aliases: ['r'],
description: 'Test reporter to use [tap|dot|xunit] (default: tap)',
},
{ name: 'silent', type: Boolean, default: false, description: 'Suppress any output except for the test report' },
{ name: 'testem-debug', type: String, description: 'File to write a debug log from testem' },
{ name: 'test-page', type: String, description: 'Test page to invoke' },
{ name: 'query', type: String, description: 'A query string to append to the test page URL.' },
],
availableOptions: buildAvailableOptions(),

rmTmp() {
if (process.platform === 'win32') {
Expand All @@ -55,3 +27,37 @@ availableOptions: [
return this._super(...arguments);
},
});

function buildAvailableOptions() {
// Whitelist options from the base class we support so we don't turn on newly
// added ones until developers have had a chance to review
const supportedNames = [
'environment',
'config-file',
'server',
'filter',
'module',
'watcher',
'reporter',
'silent',
'testem-debug',
'test-page',
'query'
];
const baseOptions = TestCommand.prototype.availableOptions;

// Pick just the ones we support
let availableOptions = baseOptions.filter(option => supportedNames.includes(option.name));
// Make our customizations
availableOptions = availableOptions.map((option) => {
// probably doesn't hurt to share un-modified options objects between
// prototypes, but let's do this just to be safe
option = Object.assign({}, option);

if (option.name === 'config-file') {
option.default = 'testem-electron.js';
}
return option;
});
return availableOptions;
}

0 comments on commit 1445f59

Please sign in to comment.