Skip to content

Commit

Permalink
feat(generate): create parent directories required for blueprints if …
Browse files Browse the repository at this point in the history
…they do not exist

fixes #3307
  • Loading branch information
Meligy committed Jan 9, 2017
1 parent 338e69b commit c927497
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/angular-cli/utilities/dynamic-path-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ module.exports = function dynamicPathParser(project, entityName) {
} else if (fs.existsSync(withPlus)) {
return withPlus;
}

throw `Invalid path: "${withoutPlus}"" is not a valid path.`

// Folder not found, create it, and return it
fs.mkdirSync(withoutPlus);
return withoutPlus;

}, parsedOutputPath.root);
outputPath = path.join(newPath, parsedOutputPath.name);
}
Expand Down
14 changes: 14 additions & 0 deletions tests/acceptance/generate-component.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,20 @@ describe('Acceptance: ng generate component', function () {
});
});

it(`non${path.sep}existing${path.sep}dir${path.sep}myComp will create dir and succeed`, () => {
const testPath =
path.join(root, 'tmp', 'foo', 'src', 'app', 'non', 'existing', 'dir', 'my-comp', 'my-comp.component.ts');
const appModule = path.join(root, 'tmp', 'foo', 'src', 'app', 'app.module.ts');
return ng(['generate', 'component', `non${path.sep}existing${path.sep}dir${path.sep}myComp`])
.then(() => expect(existsSync(testPath)).to.equal(true))
.then(() => readFile(appModule, 'utf-8'))
.then(content => {
// Expect that the app.module contains a reference to my-comp and its import.
expect(content)
.matches(/import.*MyCompComponent.*from '.\/non\/existing\/dir\/my-comp\/my-comp.component';/);
});
});

it('my-comp --inline-template', function () {
return ng(['generate', 'component', 'my-comp', '--inline-template']).then(() => {
var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.component.html');
Expand Down

0 comments on commit c927497

Please sign in to comment.