Skip to content

Commit 88e9a58

Browse files
committed
feat(generate): create parent directories required for blueprints if they do not exist
fixes angular#3307
1 parent 338e69b commit 88e9a58

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

packages/angular-cli/utilities/dynamic-path-parser.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ module.exports = function dynamicPathParser(project, entityName) {
3333
} else if (fs.existsSync(withPlus)) {
3434
return withPlus;
3535
}
36-
37-
throw `Invalid path: "${withoutPlus}"" is not a valid path.`
36+
37+
// Folder not found, create it, and return it
38+
fs.mkdirSync(withoutPlus);
39+
return withoutPlus;
40+
3841
}, parsedOutputPath.root);
3942
outputPath = path.join(newPath, parsedOutputPath.name);
4043
}

tests/acceptance/generate-component.spec.js

+14
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,20 @@ describe('Acceptance: ng generate component', function () {
178178
});
179179
});
180180

181+
it(`nonExistingDir${path.sep}myComp will create dir and succeed`, () => {
182+
const testPath =
183+
path.join(root, 'tmp', 'foo', 'src', 'app', 'non-existing-dir', 'my-comp', 'my-comp.component.ts');
184+
const appModule = path.join(root, 'tmp', 'foo', 'src', 'app', 'app.module.ts');
185+
return ng(['generate', 'component', `non-existing-dir${path.sep}myComp`])
186+
.then(() => expect(existsSync(testPath)).to.equal(true))
187+
.then(() => readFile(appModule, 'utf-8'))
188+
.then(content => {
189+
// Expect that the app.module contains a reference to my-comp and its import.
190+
expect(content)
191+
.matches(/import.*MyCompComponent.*from '.\/non-existing-dir\/my-comp\/my-comp.component';/);
192+
});
193+
});
194+
181195
it('my-comp --inline-template', function () {
182196
return ng(['generate', 'component', 'my-comp', '--inline-template']).then(() => {
183197
var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.component.html');

0 commit comments

Comments
 (0)