Skip to content

Commit e77dfcf

Browse files
author
Kelly Selden
committed
refactor getArgs
1 parent c2d8c5f commit e77dfcf

2 files changed

Lines changed: 59 additions & 29 deletions

File tree

src/get-start-and-end-commands.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,39 +38,39 @@ module.exports = function getStartAndEndCommands({
3838
};
3939
};
4040

41-
function buildCommand(projectName, blueprint) {
41+
function getArgs(projectName, blueprint) {
4242
let isCustomBlueprint = blueprint.name !== 'ember-cli';
4343

44-
let command = `new ${projectName} -sn -sg`;
45-
46-
let blueprintPath;
44+
let _blueprint;
4745
if (isCustomBlueprint) {
48-
blueprintPath = blueprint.path;
46+
_blueprint = blueprint.path;
4947
} else if (blueprint.type === 'addon') {
50-
blueprintPath = 'addon';
48+
_blueprint = 'addon';
5149
} else {
52-
blueprintPath = 'app';
50+
_blueprint = 'app';
5351
}
5452

55-
command += ` -b ${blueprintPath}`;
56-
57-
if (blueprint.options.length) {
58-
command += ` ${blueprint.options.join(' ')}`;
59-
}
60-
61-
return command;
53+
return [
54+
'new',
55+
projectName,
56+
'-sn',
57+
'-sg',
58+
'-b',
59+
_blueprint,
60+
...blueprint.options
61+
];
6262
}
6363

6464
function createProjectFromCache({
6565
packageRoot,
6666
options
6767
}) {
68-
let command = buildCommand(options.projectName, options.blueprint);
68+
let args = getArgs(options.projectName, options.blueprint);
6969

7070
return async function createProject(cwd) {
7171
await utils.spawn('node', [
7272
path.join(packageRoot, 'bin/ember'),
73-
...command.split(' ')
73+
...args
7474
], {
7575
cwd
7676
});
@@ -87,7 +87,7 @@ function createProjectFromRemote({
8787
}) {
8888
return async function createProject(cwd) {
8989
if (options.blueprint) {
90-
let command = buildCommand(options.projectName, options.blueprint);
90+
let command = getArgs(options.projectName, options.blueprint).join(' ');
9191

9292
let isCustomBlueprint = options.blueprint.name !== 'ember-cli';
9393

@@ -146,7 +146,7 @@ module.exports.installAddonBlueprint = async function installAddonBlueprint({
146146
name: 'ember-cli'
147147
};
148148

149-
let command = buildCommand(projectName, loadSafeBlueprint(defaultBlueprint));
149+
let command = getArgs(projectName, loadSafeBlueprint(defaultBlueprint)).join(' ');
150150

151151
await fs.remove(path.join(cwd, projectName));
152152

@@ -188,4 +188,4 @@ async function appendNodeModulesIgnore({
188188
}
189189

190190
module.exports.appendNodeModulesIgnore = appendNodeModulesIgnore;
191-
module.exports.buildCommand = buildCommand;
191+
module.exports.getArgs = getArgs;

test/unit/get-start-and-end-commands-test.js

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const utils = require('../../src/utils');
99
const loadSafeBlueprint = require('../../src/load-safe-blueprint');
1010

1111
const {
12-
buildCommand
12+
getArgs
1313
} = _getStartAndEndCommands;
1414

1515
const projectName = 'my-custom-app';
@@ -391,7 +391,7 @@ describe(_getStartAndEndCommands, function() {
391391
});
392392
});
393393

394-
describe(buildCommand, function() {
394+
describe(getArgs, function() {
395395
let projectName = 'my-project';
396396

397397
it('works for default app', function() {
@@ -401,9 +401,16 @@ describe(_getStartAndEndCommands, function() {
401401
options: []
402402
};
403403

404-
let command = buildCommand(projectName, blueprint);
404+
let args = getArgs(projectName, blueprint);
405405

406-
expect(command).to.equal('new my-project -sn -sg -b app');
406+
expect(args).to.deep.equal([
407+
'new',
408+
'my-project',
409+
'-sn',
410+
'-sg',
411+
'-b',
412+
'app'
413+
]);
407414
});
408415

409416
it('works for default addon', function() {
@@ -413,9 +420,16 @@ describe(_getStartAndEndCommands, function() {
413420
options: []
414421
};
415422

416-
let command = buildCommand(projectName, blueprint);
423+
let args = getArgs(projectName, blueprint);
417424

418-
expect(command).to.equal('new my-project -sn -sg -b addon');
425+
expect(args).to.deep.equal([
426+
'new',
427+
'my-project',
428+
'-sn',
429+
'-sg',
430+
'-b',
431+
'addon'
432+
]);
419433
});
420434

421435
it('works for custom app', function() {
@@ -425,9 +439,16 @@ describe(_getStartAndEndCommands, function() {
425439
options: []
426440
};
427441

428-
let command = buildCommand(projectName, blueprint);
442+
let args = getArgs(projectName, blueprint);
429443

430-
expect(command).to.equal('new my-project -sn -sg -b /path/to/my-blueprint');
444+
expect(args).to.deep.equal([
445+
'new',
446+
'my-project',
447+
'-sn',
448+
'-sg',
449+
'-b',
450+
'/path/to/my-blueprint'
451+
]);
431452
});
432453

433454
it('handles options', function() {
@@ -440,9 +461,18 @@ describe(_getStartAndEndCommands, function() {
440461
]
441462
};
442463

443-
let command = buildCommand(projectName, blueprint);
464+
let args = getArgs(projectName, blueprint);
444465

445-
expect(command).to.equal('new my-project -sn -sg -b app --my-option-1 --my-option-2');
466+
expect(args).to.deep.equal([
467+
'new',
468+
'my-project',
469+
'-sn',
470+
'-sg',
471+
'-b',
472+
'app',
473+
'--my-option-1',
474+
'--my-option-2'
475+
]);
446476
});
447477
});
448478
});

0 commit comments

Comments
 (0)