UNPKG

1.96 kBJavaScriptView Raw
1'use strict';
2
3const findByName = require('../utils/find-by-name');
4const debug = require('debug')('ember-try:commands:try-one');
5
6module.exports = {
7 name: 'try:one',
8 description:
9 'Run any `ember` command with the specified dependency scenario. This optional command is preceded by " --- " and will default to `ember test`',
10 works: 'insideProject',
11
12 anonymousOptions: ['<scenario>'],
13
14 availableOptions: [
15 { name: 'skip-cleanup', type: Boolean, default: false },
16 { name: 'config-path', type: String },
17 ],
18
19 _getConfig: require('../utils/config'),
20 _TryEachTask: require('../tasks/try-each'),
21
22 getCommand(_argv) {
23 let args = (_argv || this._commandLineArguments()).slice();
24 let separatorIndex = args.indexOf('---');
25 if (separatorIndex === -1) {
26 return [];
27 }
28
29 return args.slice(separatorIndex + 1);
30 },
31
32 async run(commandOptions, rawArgs) {
33 let scenarioName = rawArgs[0];
34
35 debug('Scenario argument: %s', scenarioName);
36 debug('Command options:\n', commandOptions);
37
38 let commandArgs = this.getCommand();
39
40 debug('Command specified on command line: %s', commandArgs.join(' '));
41
42 if (!scenarioName) {
43 throw new Error('The `ember try:one` command requires a ' + 'scenario name to be specified.');
44 }
45
46 let config = await this._getConfig({
47 project: this.project,
48 configPath: commandOptions.configPath,
49 });
50
51 debug('Config: %s', JSON.stringify(config));
52
53 let scenario = findByName(config.scenarios, scenarioName);
54 if (!scenario) {
55 throw new Error(
56 'The `ember try:one` command requires a scenario ' + 'specified in the config.'
57 );
58 }
59
60 let tryEachTask = new this._TryEachTask({
61 ui: this.ui,
62 project: this.project,
63 config,
64 commandArgs,
65 });
66
67 return await tryEachTask.run([scenario], { skipCleanup: commandOptions.skipCleanup });
68 },
69
70 _commandLineArguments() {
71 return process.argv;
72 },
73};