Skip to content

Commit 4d77de0

Browse files
committed
Move logic out of ember-cli commands
1 parent e0d196e commit 4d77de0

20 files changed

+297
-342
lines changed

Diff for: index.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ module.exports = {
44
name: 'ember-try',
55

66
includedCommands() {
7-
return require('./lib/commands');
7+
return {
8+
'try:reset': require('./lib/ember-cli-commands/reset'),
9+
'try:each': require('./lib/ember-cli-commands/try-each'),
10+
'try:one': require('./lib/ember-cli-commands/try-one'),
11+
'try:ember': require('./lib/ember-cli-commands/try-ember'),
12+
'try:config': require('./lib/ember-cli-commands/config'),
13+
};
814
},
915
};

Diff for: lib/commands/config.js

-23
This file was deleted.

Diff for: lib/commands/config.mjs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import getConfig from '../utils/config.js';
2+
import { log } from '../utils/console.js';
3+
4+
export async function config({ configPath, cwd }) {
5+
const config = await getConfig({ configPath, cwd });
6+
7+
log(JSON.stringify(config, null, 2));
8+
}

Diff for: lib/commands/reset.js

-20
This file was deleted.

Diff for: lib/commands/reset.mjs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import ResetTask from '../tasks/reset.js';
2+
import getConfig from '../utils/config.js';
3+
4+
export async function reset({ configPath, cwd }) {
5+
const config = await getConfig({ configPath, cwd });
6+
const resetTask = new ResetTask({ config, cwd });
7+
8+
await resetTask.run();
9+
}

Diff for: lib/commands/try-each.js

-36
This file was deleted.

Diff for: lib/commands/try-each.mjs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import TryEachTask from '../tasks/try-each.js';
2+
import getConfig from '../utils/config.js';
3+
4+
export async function tryEach({
5+
configPath,
6+
cwd,
7+
skipCleanup,
8+
9+
// For testing purposes:
10+
_getConfig = getConfig,
11+
_TryEachTask = TryEachTask,
12+
}) {
13+
const config = await _getConfig({ configPath, cwd });
14+
const tryEachTask = new _TryEachTask({ config, cwd });
15+
16+
await tryEachTask.run(config.scenarios, { skipCleanup });
17+
}

Diff for: lib/commands/try-ember.js

-45
This file was deleted.

Diff for: lib/commands/try-ember.mjs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import TryEachTask from '../tasks/try-each.js';
2+
import getConfig from '../utils/config.js';
3+
4+
export async function tryEmber({
5+
configPath,
6+
cwd,
7+
ember,
8+
skipCleanup,
9+
10+
// For testing purposes:
11+
_getConfig = getConfig,
12+
_TryEachTask = TryEachTask,
13+
}) {
14+
const config = await _getConfig({
15+
configPath,
16+
cwd,
17+
versionCompatibility: { ember },
18+
});
19+
20+
const tryEachTask = new _TryEachTask({ config, cwd });
21+
22+
await tryEachTask.run(config.scenarios, { skipCleanup });
23+
}

Diff for: lib/commands/try-one.js

-72
This file was deleted.

Diff for: lib/commands/try-one.mjs

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import TryEachTask from '../tasks/try-each.js';
2+
import getConfig from '../utils/config.js';
3+
4+
export async function tryOne({
5+
configPath,
6+
cwd,
7+
scenarioName,
8+
skipCleanup,
9+
10+
// For testing purposes:
11+
_args = process.argv,
12+
_getConfig = getConfig,
13+
_TryEachTask = TryEachTask,
14+
}) {
15+
const config = await _getConfig({ configPath, cwd });
16+
const scenario = config.scenarios.find((s) => s.name === scenarioName);
17+
18+
if (scenario === undefined) {
19+
throw new Error('The `try:one` command requires a scenario name specified in the config.');
20+
}
21+
22+
const tryEachTask = new _TryEachTask({
23+
commandArgs: getCommandArgs(_args),
24+
config,
25+
cwd,
26+
});
27+
28+
await tryEachTask.run([scenario], { skipCleanup });
29+
}
30+
31+
export function getCommandArgs(args) {
32+
const separatorIndex = args.indexOf('---');
33+
34+
if (separatorIndex === -1) {
35+
return [];
36+
} else {
37+
return args.slice(separatorIndex + 1);
38+
}
39+
}

Diff for: lib/ember-cli-commands/config.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
module.exports = {
4+
name: 'try:config',
5+
description: 'Displays the config that will be used',
6+
works: 'insideProject',
7+
availableOptions: [{ name: 'config-path', type: String }],
8+
9+
async run({ configPath }) {
10+
const { config } = await import('../commands/config.mjs');
11+
12+
await config({ configPath, cwd: this.project.root });
13+
},
14+
};
File renamed without changes.

Diff for: lib/ember-cli-commands/reset.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
module.exports = {
4+
name: 'try:reset',
5+
description: 'Resets dependencies to their committed state. For when things get messy.',
6+
works: 'insideProject',
7+
availableOptions: [{ name: 'config-path', type: String }],
8+
9+
async run({ configPath }) {
10+
const { reset } = await import('../commands/reset.mjs');
11+
12+
await reset({ configPath, cwd: this.project.root });
13+
},
14+
};

Diff for: lib/ember-cli-commands/try-each.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
3+
module.exports = {
4+
name: 'try:each',
5+
description:
6+
'Runs each of the dependency scenarios specified in config with the specified command. The command defaults to `ember test`',
7+
works: 'insideProject',
8+
9+
availableOptions: [
10+
{ name: 'config-path', type: String },
11+
{ name: 'skip-cleanup', type: Boolean, default: false },
12+
],
13+
14+
async run({ configPath, skipCleanup }) {
15+
const { tryEach } = await import('../commands/try-each.mjs');
16+
17+
await tryEach({ configPath, cwd: this.project.root, skipCleanup });
18+
},
19+
};

Diff for: lib/ember-cli-commands/try-ember.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
module.exports = {
4+
name: 'try:ember',
5+
description:
6+
'Runs with each Ember version matching the semver statement given. The command defaults to `ember test`',
7+
works: 'insideProject',
8+
9+
anonymousOptions: ['<ember-semver-statement>'],
10+
11+
availableOptions: [
12+
{ name: 'config-path', type: String },
13+
{ name: 'skip-cleanup', type: Boolean, default: false },
14+
],
15+
16+
async run({ configPath, skipCleanup }, [ember]) {
17+
const { tryEmber } = await import('../commands/try-ember.mjs');
18+
19+
await tryEmber({ configPath, cwd: this.project.root, ember, skipCleanup });
20+
},
21+
};

0 commit comments

Comments
 (0)