Skip to content

Commit 09c6d2d

Browse files
author
Kelly Selden
committed
consolidate overwriteBlueprintFiles calls
1 parent b521176 commit 09c6d2d

2 files changed

Lines changed: 38 additions & 19 deletions

File tree

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

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -123,39 +123,31 @@ function getArgs({
123123
];
124124
}
125125

126-
module.exports.spawn = async function spawn(command, args, options) {
126+
module.exports.spawn = function spawn(command, args, options) {
127127
debug(`${command} ${args.join(' ')}`);
128128

129-
let ps = execa(command, args, {
129+
return execa(command, args, {
130130
stdio: ['pipe', 'pipe', 'inherit'],
131131
...options
132132
});
133-
134-
overwriteBlueprintFiles(ps);
135-
136-
await ps;
137133
};
138134

139-
module.exports.npx = async function npx(args, options) {
140-
let ps = utils.npx(args.join(' '), options);
141-
142-
overwriteBlueprintFiles(ps);
143-
144-
await ps;
135+
module.exports.npx = function npx(args, options) {
136+
return utils.npx(args.join(' '), options);
145137
};
146138

147-
async function runEmberLocally({
139+
function runEmberLocally({
148140
packageRoot,
149141
cwd,
150142
args
151143
}) {
152-
await module.exports.spawn('node', [
144+
return module.exports.spawn('node', [
153145
path.join(packageRoot, 'bin/ember'),
154146
...args
155147
], { cwd });
156148
}
157149

158-
async function runEmberRemotely({
150+
function runEmberRemotely({
159151
cwd,
160152
blueprint,
161153
args
@@ -169,7 +161,7 @@ async function runEmberRemotely({
169161
args = ['-p', `ember-cli@${blueprint.version}`, 'ember', ...args];
170162
}
171163

172-
await module.exports.npx(args, { cwd });
164+
return module.exports.npx(args, { cwd });
173165
}
174166

175167
function createProject(runEmber) {
@@ -196,12 +188,16 @@ function createProject(runEmber) {
196188
blueprint
197189
});
198190

199-
await runEmber({
191+
let ps = runEmber({
200192
packageRoot,
201193
cwd: _cwd,
202194
blueprint,
203195
args
204196
});
197+
198+
module.exports.overwriteBlueprintFiles(ps);
199+
200+
await ps;
205201
}
206202

207203
if (!blueprint || !blueprint.isBaseBlueprint) {
@@ -278,3 +274,4 @@ async function appendNodeModulesIgnore({
278274

279275
module.exports.appendNodeModulesIgnore = appendNodeModulesIgnore;
280276
module.exports.getArgs = getArgs;
277+
module.exports.overwriteBlueprintFiles = overwriteBlueprintFiles;

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ describe(_getStartAndEndCommands, function() {
3333
let npxStub;
3434
let spawnStub;
3535
let readdirStub;
36+
let overwriteBlueprintFilesStub;
3637
let installAddonBlueprintStub;
3738
let appendNodeModulesIgnoreStub;
3839

3940
beforeEach(function() {
40-
npxStub = sinon.stub(_getStartAndEndCommands, 'npx').resolves();
41-
spawnStub = sinon.stub(_getStartAndEndCommands, 'spawn').resolves();
41+
npxStub = sinon.stub(_getStartAndEndCommands, 'npx').returns('test npx');
42+
spawnStub = sinon.stub(_getStartAndEndCommands, 'spawn').returns('test spawn');
4243
readdirStub = sinon.stub(utils, 'readdir').resolves(['foo']);
44+
overwriteBlueprintFilesStub = sinon.stub(_getStartAndEndCommands, 'overwriteBlueprintFiles');
4345
installAddonBlueprintStub = sinon.stub(_getStartAndEndCommands, 'installAddonBlueprint').resolves();
4446
appendNodeModulesIgnoreStub = sinon.stub(_getStartAndEndCommands, 'appendNodeModulesIgnore').resolves();
4547
});
@@ -131,6 +133,8 @@ describe(_getStartAndEndCommands, function() {
131133
cwd
132134
}
133135
]]);
136+
137+
expect(overwriteBlueprintFilesStub.args).to.deep.equal([['test spawn']]);
134138
});
135139

136140
it('can create a partial project from cache', async function() {
@@ -186,6 +190,8 @@ describe(_getStartAndEndCommands, function() {
186190
}
187191
]
188192
]);
193+
194+
expect(overwriteBlueprintFilesStub.args).to.deep.equal([['test spawn'], ['test spawn']]);
189195
});
190196

191197
it('can create a base project from remote', async function() {
@@ -217,6 +223,8 @@ describe(_getStartAndEndCommands, function() {
217223
cwd
218224
}
219225
]]);
226+
227+
expect(overwriteBlueprintFilesStub.args).to.deep.equal([['test npx']]);
220228
});
221229

222230
it('can create a partial project from remote', async function() {
@@ -271,6 +279,8 @@ describe(_getStartAndEndCommands, function() {
271279
}
272280
]
273281
]);
282+
283+
expect(overwriteBlueprintFilesStub.args).to.deep.equal([['test npx'], ['test npx']]);
274284
});
275285

276286
describe('custom blueprint', function() {
@@ -404,6 +414,8 @@ describe(_getStartAndEndCommands, function() {
404414
}
405415
]]);
406416

417+
expect(overwriteBlueprintFilesStub.args).to.deep.equal([['test spawn']]);
418+
407419
expect(installAddonBlueprintStub).to.not.be.called;
408420

409421
expect(appendNodeModulesIgnoreStub.args).to.deep.equal([[{
@@ -467,6 +479,8 @@ describe(_getStartAndEndCommands, function() {
467479
]
468480
]);
469481

482+
expect(overwriteBlueprintFilesStub.args).to.deep.equal([['test spawn'], ['test spawn']]);
483+
470484
expect(installAddonBlueprintStub).to.not.be.called;
471485

472486
expect(appendNodeModulesIgnoreStub.args).to.deep.equal([[{
@@ -509,6 +523,8 @@ describe(_getStartAndEndCommands, function() {
509523
}
510524
]]);
511525

526+
expect(overwriteBlueprintFilesStub.args).to.deep.equal([['test npx']]);
527+
512528
expect(installAddonBlueprintStub).to.not.be.called;
513529

514530
expect(appendNodeModulesIgnoreStub.args).to.deep.equal([[{
@@ -569,6 +585,8 @@ describe(_getStartAndEndCommands, function() {
569585
]
570586
]);
571587

588+
expect(overwriteBlueprintFilesStub.args).to.deep.equal([['test npx'], ['test npx']]);
589+
572590
expect(installAddonBlueprintStub).to.not.be.called;
573591

574592
expect(appendNodeModulesIgnoreStub.args).to.deep.equal([[{
@@ -618,6 +636,8 @@ describe(_getStartAndEndCommands, function() {
618636
]
619637
]);
620638

639+
expect(overwriteBlueprintFilesStub.args).to.deep.equal([['test spawn']]);
640+
621641
expect(installAddonBlueprintStub.args).to.deep.equal([[{
622642
projectRoot,
623643
blueprint: {
@@ -669,6 +689,8 @@ describe(_getStartAndEndCommands, function() {
669689
]
670690
]);
671691

692+
expect(overwriteBlueprintFilesStub.args).to.deep.equal([['test npx']]);
693+
672694
expect(installAddonBlueprintStub.args).to.deep.equal([[{
673695
projectRoot,
674696
blueprint: {

0 commit comments

Comments
 (0)