Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(generate): create parent directories required for blueprints if they do not exist #3912

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/angular-cli/utilities/dynamic-path-parser.js
Original file line number Diff line number Diff line change
@@ -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);
}
14 changes: 14 additions & 0 deletions tests/acceptance/generate-component.spec.js
Original file line number Diff line number Diff line change
@@ -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');
11 changes: 6 additions & 5 deletions tests/e2e/tests/generate/component/component-path-case.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import {join} from 'path';
import {ng} from '../../../utils/process';
import {expectFileToExist, createDir} from '../../../utils/fs';
import {expectFileToExist} from '../../../utils/fs';


export default function() {
const rootDir = join('src', 'app', 'Upper-Dir');
createDir(rootDir);
const upperDirs = join('non', 'existing', 'dir');
const rootDir = join('src', 'app', upperDirs);

const componentDir = join(rootDir, 'test-component');
const componentTwoDir = join(rootDir, 'test-component-two');

return ng('generate', 'component', 'Upper-Dir/test-component')
return ng('generate', 'component', `${upperDirs}/test-component`)
.then(() => expectFileToExist(componentDir))
.then(() => expectFileToExist(join(componentDir, 'test-component.component.ts')))
.then(() => expectFileToExist(join(componentDir, 'test-component.component.spec.ts')))
.then(() => expectFileToExist(join(componentDir, 'test-component.component.html')))
.then(() => expectFileToExist(join(componentDir, 'test-component.component.css')))
.then(() => ng('generate', 'component', 'Upper-Dir/Test-Component-Two'))
.then(() => ng('generate', 'component', `${upperDirs}/Test-Component-Two`))
.then(() => expectFileToExist(join(componentTwoDir, 'test-component-two.component.ts')))
.then(() => expectFileToExist(join(componentTwoDir, 'test-component-two.component.spec.ts')))
.then(() => expectFileToExist(join(componentTwoDir, 'test-component-two.component.html')))