Skip to content

feat(module): component optional when generating module #3389

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

Merged
merged 25 commits into from
Dec 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8600b09
change URL query key name
baruchvlz Dec 4, 2016
62f8957
generate component with module made optional
baruchvlz Dec 4, 2016
41d0d87
revert changes done to module cause open PR
baruchvlz Dec 4, 2016
d6be3ea
components when generating module is optional
baruchvlz Dec 4, 2016
8bfad42
Merge remote-tracking branch 'angular/master' into 3365-FR
baruchvlz Dec 5, 2016
cedbf9f
Merge pull request #1 from baruchvlz/3365-FR
baruchvlz Dec 5, 2016
005352d
tests updated for component flag
baruchvlz Dec 5, 2016
d7b6c09
Merge pull request #2 from baruchvlz/3365-FR
baruchvlz Dec 5, 2016
64f58b4
fix parent/child compnent test to fit new flag
baruchvlz Dec 5, 2016
aa5252b
updated test for parent/child module generate
baruchvlz Dec 5, 2016
b9cc0b8
Merge pull request #3 from baruchvlz/3365-FR
baruchvlz Dec 5, 2016
cf74ea1
removed component testing from basic module e2e
baruchvlz Dec 5, 2016
69acc9a
adjusted e2e test for generate module
baruchvlz Dec 5, 2016
00c25df
Merge pull request #4 from baruchvlz/3365-FR
baruchvlz Dec 5, 2016
66d73e6
Updating branch with beta22-1
baruchvlz Dec 5, 2016
320a489
updating branch with angular/master
baruchvlz Dec 6, 2016
2387525
ng g m creates module only with routing flag
baruchvlz Dec 7, 2016
172dc6e
unit test for new generate module behavior
baruchvlz Dec 7, 2016
5c52d91
e2e tests for g m new behavior
baruchvlz Dec 7, 2016
373de80
update branch with angular/master
baruchvlz Dec 7, 2016
4af16a9
remove spec test
baruchvlz Dec 7, 2016
c97a322
shorten test module name to keep 100 char limit
baruchvlz Dec 7, 2016
c803f23
Merge branch 'master' into master
baruchvlz Dec 8, 2016
64299ad
Merge branch 'master' into master
baruchvlz Dec 8, 2016
fe6a0e1
Merge branch 'master' into master
baruchvlz Dec 8, 2016
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
22 changes: 12 additions & 10 deletions packages/angular-cli/blueprints/module/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,18 @@ module.exports = {

afterInstall: function (options) {
// Note that `this.generatePath` already contains `this.dasherizedModuleName`
// So, the path will end like `name/name`,
// So, the path will end like `name/name`,
// which is correct for `name.component.ts` created in module `name`
var componentPath = path.join(this.generatePath, this.dasherizedModuleName);
options.entity.name = path.relative(this.dynamicPath.appRoot, componentPath);
options.flat = true;
options.route = false;
options.inlineTemplate = false;
options.inlineStyle = false;
options.prefix = true;
options.spec = true;
return Blueprint.load(path.join(__dirname, '../component')).install(options);
if (this.options && this.options.routing) {
var componentPath = path.join(this.generatePath, this.dasherizedModuleName);
options.entity.name = path.relative(this.dynamicPath.appRoot, componentPath);
options.flat = true;
options.route = false;
options.inlineTemplate = false;
options.inlineStyle = false;
options.prefix = true;
options.spec = true;
return Blueprint.load(path.join(__dirname, '../component')).install(options);
}
}
};
21 changes: 21 additions & 0 deletions tests/acceptance/generate-module.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,19 @@ describe('Acceptance: ng generate module', function () {
return ng(['generate', 'module', 'my-module']).then(() => {
expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.ts'))).to.equal(true);
expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.spec.ts'))).to.equal(false);
expect(existsSync(path.join(testPath, 'my-module', 'my-module.component.ts'))).to.equal(false);
});
});

it('ng generate module generate routing and component files when passed flag --routing', function () {
return ng(['generate', 'module', 'my-module', '--routing']).then( () => {
expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.ts'))).to.equal(true);
expect(existsSync(path.join(testPath, 'my-module', 'my-module-routing.module.ts'))).to.equal(true);
expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.spec.ts'))).to.equal(false);
expect(existsSync(path.join(testPath, 'my-module', 'my-module.component.ts'))).to.equal(true);
})
});

it('ng generate module my-module --spec', function () {
return ng(['generate', 'module', 'my-module', '--spec']).then(() => {
expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.ts'))).to.equal(true);
Expand All @@ -57,6 +67,17 @@ describe('Acceptance: ng generate module', function () {
ng(['generate', 'module', 'parent/child']).then(() => {
expect(existsSync(path.join(testPath, 'parent/child', 'child.module.ts'))).to.equal(true);
expect(existsSync(path.join(testPath, 'parent/child', 'child.module.spec.ts'))).to.equal(false);
expect(existsSync(path.join(testPath, 'parent/child', 'child.component.ts'))).to.equal(false);
})
);
});

it('ng generate module should generate parent/child module with routing and component files when passed --routing flag', function () {
return ng(['generate', 'module', 'parent']).then(() =>
ng(['generate', 'module', 'parent/child', '--routing']).then(() => {
expect(existsSync(path.join(testPath, 'parent/child', 'child.module.ts'))).to.equal(true);
expect(existsSync(path.join(testPath, 'parent/child', 'child-routing.module.ts'))).to.equal(true);
expect(existsSync(path.join(testPath, 'parent/child', 'child.module.spec.ts'))).to.equal(false);
expect(existsSync(path.join(testPath, 'parent/child', 'child.component.ts'))).to.equal(true);
})
);
Expand Down
16 changes: 7 additions & 9 deletions tests/e2e/tests/generate/module/module-basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ import {expectToFail} from '../../../utils/utils';


export default function() {
const moduleDir = join('src', 'app', 'test-module');
const moduleDir = join('src', 'app', 'test');

return ng('generate', 'module', 'test-module')
return ng('generate', 'module', 'test')
.then(() => expectFileToExist(moduleDir))
.then(() => expectFileToExist(join(moduleDir, 'test-module.module.ts')))
.then(() => expectToFail(() => expectFileToExist(join(moduleDir, 'test-module.routing.ts'))))
.then(() => expectFileToExist(join(moduleDir, 'test-module.component.ts')))
.then(() => expectFileToExist(join(moduleDir, 'test-module.component.spec.ts')))
.then(() => expectFileToExist(join(moduleDir, 'test-module.component.html')))
.then(() => expectFileToExist(join(moduleDir, 'test-module.component.css')))
.then(() => expectFileToMatch(join(moduleDir, 'test-module.module.ts'), 'TestModuleComponent'))
.then(() => expectFileToExist(join(moduleDir, 'test.module.ts')))
.then(() => expectToFail(() => expectFileToExist(join(moduleDir, 'test-routing.module.ts'))))
.then(() => expectToFail(() => expectFileToExist(join(moduleDir, 'test.component.ts'))))
.then(() => expectToFail(() => expectFileToExist(join(moduleDir, 'test.spec.ts'))))
.then(() => expectFileToMatch(join(moduleDir, 'test.module.ts'), 'TestModule'))

// Try to run the unit tests.
.then(() => ng('test', '--single-run'));
Expand Down
19 changes: 10 additions & 9 deletions tests/e2e/tests/generate/module/module-routing.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import {join} from 'path';
import {ng} from '../../../utils/process';
import {expectFileToExist} from '../../../utils/fs';
import {expectToFail} from '../../../utils/utils';


export default function() {
const moduleDir = join('src', 'app', 'test-module');
const moduleDir = join('src', 'app', 'test');

return ng('generate', 'module', 'test-module', '--routing')
return ng('generate', 'module', 'test', '--routing')
.then(() => expectFileToExist(moduleDir))
.then(() => expectFileToExist(join(moduleDir, 'test-module.module.ts')))
.then(() => expectFileToExist(join(moduleDir, 'test-module-routing.module.ts')))
.then(() => expectFileToExist(join(moduleDir, 'test-module.component.ts')))
.then(() => expectFileToExist(join(moduleDir, 'test-module.component.spec.ts')))
.then(() => expectFileToExist(join(moduleDir, 'test-module.component.html')))
.then(() => expectFileToExist(join(moduleDir, 'test-module.component.css')))

.then(() => expectFileToExist(join(moduleDir, 'test.module.ts')))
.then(() => expectFileToExist(join(moduleDir, 'test-routing.module.ts')))
.then(() => expectFileToExist(join(moduleDir, 'test.component.ts')))
.then(() => expectFileToExist(join(moduleDir, 'test.component.spec.ts')))
.then(() => expectFileToExist(join(moduleDir, 'test.component.html')))
.then(() => expectFileToExist(join(moduleDir, 'test.component.css')))
.then(() => expectToFail(() => expectFileToExist(join(moduleDir, 'test.spec.ts'))))
// Try to run the unit tests.
.then(() => ng('test', '--single-run'));
}