Skip to content

Commit b521176

Browse files
author
Kelly Selden
committed
reuse projectRoot
1 parent 20d78e8 commit b521176

2 files changed

Lines changed: 18 additions & 29 deletions

File tree

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

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,13 @@ function createProject(runEmber) {
182182
}
183183
}) => {
184184
return async function createProject(cwd) {
185+
let projectRoot = path.join(cwd, projectName);
186+
185187
async function _runEmber(blueprint) {
186188
let _cwd = cwd;
187189

188190
if (!blueprint.isBaseBlueprint) {
189-
_cwd = path.join(_cwd, projectName);
191+
_cwd = projectRoot;
190192
}
191193

192194
let args = getArgs({
@@ -209,8 +211,7 @@ function createProject(runEmber) {
209211
if (blueprint) {
210212
if (await isDefaultAddonBlueprint(blueprint)) {
211213
await module.exports.installAddonBlueprint({
212-
cwd,
213-
projectName,
214+
projectRoot,
214215
blueprint
215216
});
216217
} else {
@@ -221,23 +222,19 @@ function createProject(runEmber) {
221222
if (!(blueprint && isDefaultBlueprint(blueprint))) {
222223
// This might not be needed anymore.
223224
await module.exports.appendNodeModulesIgnore({
224-
cwd,
225-
projectName
225+
projectRoot
226226
});
227227
}
228228

229-
return path.join(cwd, projectName);
229+
return projectRoot;
230230
};
231231
};
232232
}
233233

234234
module.exports.installAddonBlueprint = async function installAddonBlueprint({
235-
cwd,
236-
projectName,
235+
projectRoot,
237236
blueprint
238237
}) {
239-
let projectRoot = path.join(cwd, projectName);
240-
241238
// `not found: ember` without this
242239
await run('npm install', { cwd: projectRoot });
243240

@@ -261,22 +258,21 @@ module.exports.installAddonBlueprint = async function installAddonBlueprint({
261258
};
262259

263260
async function appendNodeModulesIgnore({
264-
cwd,
265-
projectName
261+
projectRoot
266262
}) {
267-
if (!await fs.pathExists(path.join(cwd, projectName, 'node_modules'))) {
263+
if (!await fs.pathExists(path.join(projectRoot, 'node_modules'))) {
268264
return;
269265
}
270266

271267
let isIgnoringNodeModules;
272268
let gitignore = '';
273269
try {
274-
gitignore = await fs.readFile(path.join(cwd, projectName, '.gitignore'), 'utf8');
270+
gitignore = await fs.readFile(path.join(projectRoot, '.gitignore'), 'utf8');
275271

276272
isIgnoringNodeModules = /^\/?node_modules\/?$/m.test(gitignore);
277273
} catch (err) {}
278274
if (!isIgnoringNodeModules) {
279-
await fs.writeFile(path.join(cwd, projectName, '.gitignore'), `${gitignore}${nodeModulesIgnore}`);
275+
await fs.writeFile(path.join(projectRoot, '.gitignore'), `${gitignore}${nodeModulesIgnore}`);
280276
}
281277
}
282278

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

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,7 @@ describe(_getStartAndEndCommands, function() {
407407
expect(installAddonBlueprintStub).to.not.be.called;
408408

409409
expect(appendNodeModulesIgnoreStub.args).to.deep.equal([[{
410-
cwd,
411-
projectName
410+
projectRoot
412411
}]]);
413412
});
414413

@@ -471,8 +470,7 @@ describe(_getStartAndEndCommands, function() {
471470
expect(installAddonBlueprintStub).to.not.be.called;
472471

473472
expect(appendNodeModulesIgnoreStub.args).to.deep.equal([[{
474-
cwd,
475-
projectName
473+
projectRoot
476474
}]]);
477475
});
478476

@@ -514,8 +512,7 @@ describe(_getStartAndEndCommands, function() {
514512
expect(installAddonBlueprintStub).to.not.be.called;
515513

516514
expect(appendNodeModulesIgnoreStub.args).to.deep.equal([[{
517-
cwd,
518-
projectName
515+
projectRoot
519516
}]]);
520517
});
521518

@@ -575,8 +572,7 @@ describe(_getStartAndEndCommands, function() {
575572
expect(installAddonBlueprintStub).to.not.be.called;
576573

577574
expect(appendNodeModulesIgnoreStub.args).to.deep.equal([[{
578-
cwd,
579-
projectName
575+
projectRoot
580576
}]]);
581577
});
582578

@@ -623,8 +619,7 @@ describe(_getStartAndEndCommands, function() {
623619
]);
624620

625621
expect(installAddonBlueprintStub.args).to.deep.equal([[{
626-
cwd,
627-
projectName,
622+
projectRoot,
628623
blueprint: {
629624
path: blueprintPath,
630625
options: []
@@ -675,17 +670,15 @@ describe(_getStartAndEndCommands, function() {
675670
]);
676671

677672
expect(installAddonBlueprintStub.args).to.deep.equal([[{
678-
cwd,
679-
projectName,
673+
projectRoot,
680674
blueprint: {
681675
path: blueprintPath,
682676
options: []
683677
}
684678
}]]);
685679

686680
expect(appendNodeModulesIgnoreStub.args).to.deep.equal([[{
687-
cwd,
688-
projectName
681+
projectRoot
689682
}]]);
690683
});
691684
});

0 commit comments

Comments
 (0)