Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INTERNAL] Move logic out of ember-cli commands #1063

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ module.exports = {
name: 'ember-try',

includedCommands() {
return require('./lib/commands');
return {
'try:config': require('./lib/ember-cli-commands/config'),
'try:each': require('./lib/ember-cli-commands/try-each'),
'try:ember': require('./lib/ember-cli-commands/try-ember'),
'try:one': require('./lib/ember-cli-commands/try-one'),
'try:reset': require('./lib/ember-cli-commands/reset'),
};
},
};
23 changes: 0 additions & 23 deletions lib/commands/config.js

This file was deleted.

8 changes: 8 additions & 0 deletions lib/commands/config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import getConfig from '../utils/config.js';
import { log } from '../utils/console.js';

export async function config({ configPath, cwd }) {
const config = await getConfig({ configPath, cwd });

log(JSON.stringify(config, null, 2));
}
20 changes: 0 additions & 20 deletions lib/commands/reset.js

This file was deleted.

9 changes: 9 additions & 0 deletions lib/commands/reset.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import ResetTask from '../tasks/reset.js';
import getConfig from '../utils/config.js';

export async function reset({ configPath, cwd }) {
const config = await getConfig({ configPath, cwd });
const resetTask = new ResetTask({ config, cwd });

await resetTask.run();
}
36 changes: 0 additions & 36 deletions lib/commands/try-each.js

This file was deleted.

17 changes: 17 additions & 0 deletions lib/commands/try-each.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import TryEachTask from '../tasks/try-each.js';
import getConfig from '../utils/config.js';

export async function tryEach({
configPath,
cwd,
skipCleanup,

// For testing purposes:
_getConfig = getConfig,
_TryEachTask = TryEachTask,
}) {
const config = await _getConfig({ configPath, cwd });
const tryEachTask = new _TryEachTask({ config, cwd });

await tryEachTask.run(config.scenarios, { skipCleanup });
}
45 changes: 0 additions & 45 deletions lib/commands/try-ember.js

This file was deleted.

23 changes: 23 additions & 0 deletions lib/commands/try-ember.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import TryEachTask from '../tasks/try-each.js';
import getConfig from '../utils/config.js';

export async function tryEmber({
configPath,
cwd,
ember,
skipCleanup,

// For testing purposes:
_getConfig = getConfig,
_TryEachTask = TryEachTask,
}) {
const config = await _getConfig({
configPath,
cwd,
versionCompatibility: { ember },
});

const tryEachTask = new _TryEachTask({ config, cwd });

await tryEachTask.run(config.scenarios, { skipCleanup });
}
72 changes: 0 additions & 72 deletions lib/commands/try-one.js

This file was deleted.

39 changes: 39 additions & 0 deletions lib/commands/try-one.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import TryEachTask from '../tasks/try-each.js';
import getConfig from '../utils/config.js';

export async function tryOne({
configPath,
cwd,
scenarioName,
skipCleanup,

// For testing purposes:
_args = process.argv,
_getConfig = getConfig,
_TryEachTask = TryEachTask,
}) {
const config = await _getConfig({ configPath, cwd });
const scenario = config.scenarios.find((s) => s.name === scenarioName);

if (scenario === undefined) {
throw new Error('The `try:one` command requires a scenario name specified in the config.');
}

const tryEachTask = new _TryEachTask({
commandArgs: getCommandArgs(_args),
config,
cwd,
});

await tryEachTask.run([scenario], { skipCleanup });
}

export function getCommandArgs(args) {
const separatorIndex = args.indexOf('---');

if (separatorIndex === -1) {
return [];
} else {
return args.slice(separatorIndex + 1);
}
}
14 changes: 14 additions & 0 deletions lib/ember-cli-commands/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

module.exports = {
name: 'try:config',
description: 'Displays the config that will be used',
works: 'insideProject',
availableOptions: [{ name: 'config-path', type: String }],

async run({ configPath }) {
const { config } = await import('../commands/config.mjs');

await config({ configPath, cwd: this.project.root });
},
};
File renamed without changes.
14 changes: 14 additions & 0 deletions lib/ember-cli-commands/reset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

module.exports = {
name: 'try:reset',
description: 'Resets dependencies to their committed state. For when things get messy.',
works: 'insideProject',
availableOptions: [{ name: 'config-path', type: String }],

async run({ configPath }) {
const { reset } = await import('../commands/reset.mjs');

await reset({ configPath, cwd: this.project.root });
},
};
19 changes: 19 additions & 0 deletions lib/ember-cli-commands/try-each.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

module.exports = {
name: 'try:each',
description:
'Runs each of the dependency scenarios specified in config with the specified command. The command defaults to `ember test`',
works: 'insideProject',

availableOptions: [
{ name: 'config-path', type: String },
{ name: 'skip-cleanup', type: Boolean, default: false },
],

async run({ configPath, skipCleanup }) {
const { tryEach } = await import('../commands/try-each.mjs');

await tryEach({ configPath, cwd: this.project.root, skipCleanup });
},
};
21 changes: 21 additions & 0 deletions lib/ember-cli-commands/try-ember.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

module.exports = {
name: 'try:ember',
description:
'Runs with each Ember version matching the semver statement given. The command defaults to `ember test`',
works: 'insideProject',

anonymousOptions: ['<ember-semver-statement>'],

availableOptions: [
{ name: 'config-path', type: String },
{ name: 'skip-cleanup', type: Boolean, default: false },
],

async run({ configPath, skipCleanup }, [ember]) {
const { tryEmber } = await import('../commands/try-ember.mjs');

await tryEmber({ configPath, cwd: this.project.root, ember, skipCleanup });
},
};
Loading