Skip to content

fix(@angular/cli): remove component generation from module generation #4706

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 1 commit into from
Feb 16, 2017
Merged
Show file tree
Hide file tree
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
24 changes: 0 additions & 24 deletions packages/@angular/cli/blueprints/module/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,29 +61,5 @@ export default Blueprint.extend({
return this.generatePath;
}
};
},

afterInstall: function (options: any) {
if (this.options && this.options.routing) {

// Component folder needs to be `/{moduleName}/{ComponentName}`
// Note that we are using `flat`, so no extra dir will be created
// We need the leading `/` so the component path resolution work for both cases below:
// 1. If module name has no path (no `/`), that's going to be `/mod-name/mod-name`
// as `this.dynamicPath.dir` will be the same as `this.dynamicPath.appRoot`
// 2. If it does have `/` (like `parent/mod-name`), it'll be `/parent/mod-name/mod-name`
// as `this.dynamicPath.dir` minus `this.dynamicPath.appRoot` will be `/parent`
const moduleDir = this.dynamicPath.dir.replace(this.dynamicPath.appRoot, '')
+ path.sep + this.dasherizedModuleName;
options.entity.name = moduleDir + path.sep + this.dasherizedModuleName;
options.flat = true;

options.route = false;
options.inlineTemplate = false;
options.inlineStyle = false;
options.prefix = null;
options.spec = true;
return Blueprint.load(path.join(__dirname, '../component')).install(options);
}
}
});
12 changes: 3 additions & 9 deletions tests/acceptance/generate-module.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,14 @@ 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 () {
it('ng generate module generate routing file 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);
})
});

Expand All @@ -68,7 +66,6 @@ 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);
})
);
});
Expand All @@ -82,12 +79,11 @@ describe('Acceptance: ng generate module', function () {
ng(['generate', 'module', 'child']).then(() => {
expect(existsSync(path.join(testPath, 'sub-dir/child', 'child.module.ts'))).to.equal(true);
expect(existsSync(path.join(testPath, 'sub-dir/child', 'child.module.spec.ts'))).to.equal(false);
expect(existsSync(path.join(testPath, 'sub-dir/child', 'child.component.ts'))).to.equal(false);
})
);
});

it('ng generate module child should work in sub-dir with routing and component files when passed --routing flag', function () {
it('ng generate module child should work in sub-dir with routing file when passed --routing flag', function () {
fs.mkdirSync(path.join(testPath, './sub-dir'));
return new Promise(resolve => {
process.chdir(path.join(testPath, './sub-dir'));
Expand All @@ -97,18 +93,16 @@ describe('Acceptance: ng generate module', function () {
expect(existsSync(path.join(testPath, 'sub-dir/child', 'child.module.ts'))).to.equal(true);
expect(existsSync(path.join(testPath, 'sub-dir/child', 'child-routing.module.ts'))).to.equal(true);
expect(existsSync(path.join(testPath, 'sub-dir/child', 'child.module.spec.ts'))).to.equal(false);
expect(existsSync(path.join(testPath, 'sub-dir/child', 'child.component.ts'))).to.equal(true);
})
);
});

it('ng generate module should generate parent/child module with routing and component files when passed --routing flag', function () {
it('ng generate module should generate parent/child module with routing file 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
1 change: 0 additions & 1 deletion tests/e2e/tests/generate/module/module-basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export default function() {
.then(() => expectFileToExist(moduleDir))
.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'))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ export default function () {
.then(() => expectFileToExist(join(testPath, 'sub-dir/child')))
.then(() => expectFileToExist(join(testPath, 'sub-dir/child', 'child.module.ts')))
.then(() => expectFileToExist(join(testPath, 'sub-dir/child', 'child-routing.module.ts')))
.then(() => expectFileToExist(join(testPath, 'sub-dir/child', 'child.component.ts')))
.then(() => expectFileToExist(join(testPath, 'sub-dir/child', 'child.component.spec.ts')))
.then(() => expectFileToExist(join(testPath, 'sub-dir/child', 'child.component.html')))
.then(() => expectFileToExist(join(testPath, 'sub-dir/child', 'child.component.css')))
.then(() => expectToFail(() =>
expectFileToExist(join(testPath, 'sub-dir/child', 'child.spec.ts'))
))
Expand Down
4 changes: 0 additions & 4 deletions tests/e2e/tests/generate/module/module-routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ export default function() {
.then(() => expectFileToExist(moduleDir))
.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'));
Expand Down