Skip to content

Commit eb4eb90

Browse files
author
Kelly Selden
committed
make sure to ignore node_modules for custom blueprints
1 parent cc07c98 commit eb4eb90

2 files changed

Lines changed: 39 additions & 6 deletions

File tree

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

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
'use strict';
22

33
const path = require('path');
4+
const fs = require('fs-extra');
45
const utils = require('./utils');
56

7+
const nodeModulesIgnore = `
8+
9+
/node_modules/
10+
`;
11+
612
module.exports = function getStartAndEndCommands({
713
packageJson: { name: projectName },
814
projectOptions,
@@ -80,16 +86,18 @@ function createProjectFromRemote(command) {
8086
options
8187
}) {
8288
return async function createProject(cwd) {
83-
let npxCommand;
8489
if (options.blueprint.name !== 'ember-cli') {
85-
npxCommand = `ember-cli ${command} -b ${options.blueprint.path}`;
86-
// npxCommand = `-p github:ember-cli/ember-cli#cfb9780 ember ${command} -b ${options.blueprint.name}@${options.packageVersion}`;
90+
await utils.npx(`ember-cli ${command} -b ${options.blueprint.path}`, { cwd });
91+
// await utils.npx(`-p github:ember-cli/ember-cli#cfb9780 ember ${command} -b ${options.blueprint.name}@${options.packageVersion}`, { cwd });
92+
93+
await module.exports.appendNodeModulesIgnore({
94+
cwd,
95+
projectName: options.projectName
96+
});
8797
} else {
88-
npxCommand = `-p ember-cli@${options.packageVersion} ember ${command}`;
98+
await utils.npx(`-p ember-cli@${options.packageVersion} ember ${command}`, { cwd });
8999
}
90100

91-
await utils.npx(npxCommand, { cwd });
92-
93101
return postCreateProject({
94102
cwd,
95103
options
@@ -106,3 +114,21 @@ function postCreateProject({
106114
}) {
107115
return path.join(cwd, projectName);
108116
}
117+
118+
async function appendNodeModulesIgnore({
119+
cwd,
120+
projectName
121+
}) {
122+
let isIgnoringNodeModules;
123+
let gitignore = '';
124+
try {
125+
gitignore = await fs.readFile(path.join(cwd, projectName, '.gitignore'), 'utf8');
126+
127+
isIgnoringNodeModules = /^\/?node_modules\/?$/m.test(gitignore);
128+
} catch (err) {}
129+
if (!isIgnoringNodeModules) {
130+
await fs.writeFile(path.join(cwd, projectName, '.gitignore'), `${gitignore}${nodeModulesIgnore}`);
131+
}
132+
}
133+
134+
module.exports.appendNodeModulesIgnore = appendNodeModulesIgnore;

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ describe(_getStartAndEndCommands, function() {
2323
let sandbox;
2424
let npxStub;
2525
let spawnStub;
26+
let appendNodeModulesIgnoreStub;
2627

2728
beforeEach(function() {
2829
sandbox = sinon.createSandbox();
2930

3031
npxStub = sandbox.stub(utils, 'npx').resolves();
3132
spawnStub = sandbox.stub(utils, 'spawn').resolves();
33+
appendNodeModulesIgnoreStub = sandbox.stub(_getStartAndEndCommands, 'appendNodeModulesIgnore').resolves();
3234
});
3335

3436
afterEach(function() {
@@ -171,6 +173,11 @@ describe(_getStartAndEndCommands, function() {
171173
cwd
172174
}
173175
]]);
176+
177+
expect(appendNodeModulesIgnoreStub.args).to.deep.equal([[{
178+
cwd,
179+
projectName
180+
}]]);
174181
});
175182
});
176183

0 commit comments

Comments
 (0)