Skip to content

Commit 977784c

Browse files
BroccoZhicheng Wang
authored and
Zhicheng Wang
committed
fix(@angular/cli): remove component generation from module generation (angular#4706)
Fixes angular#4209 BREAKING CHANGE: Generating a module with routing will no longer generate an associated component.
1 parent 07b87b3 commit 977784c

File tree

5 files changed

+3
-42
lines changed

5 files changed

+3
-42
lines changed

packages/@angular/cli/blueprints/module/index.ts

-24
Original file line numberDiff line numberDiff line change
@@ -61,29 +61,5 @@ export default Blueprint.extend({
6161
return this.generatePath;
6262
}
6363
};
64-
},
65-
66-
afterInstall: function (options: any) {
67-
if (this.options && this.options.routing) {
68-
69-
// Component folder needs to be `/{moduleName}/{ComponentName}`
70-
// Note that we are using `flat`, so no extra dir will be created
71-
// We need the leading `/` so the component path resolution work for both cases below:
72-
// 1. If module name has no path (no `/`), that's going to be `/mod-name/mod-name`
73-
// as `this.dynamicPath.dir` will be the same as `this.dynamicPath.appRoot`
74-
// 2. If it does have `/` (like `parent/mod-name`), it'll be `/parent/mod-name/mod-name`
75-
// as `this.dynamicPath.dir` minus `this.dynamicPath.appRoot` will be `/parent`
76-
const moduleDir = this.dynamicPath.dir.replace(this.dynamicPath.appRoot, '')
77-
+ path.sep + this.dasherizedModuleName;
78-
options.entity.name = moduleDir + path.sep + this.dasherizedModuleName;
79-
options.flat = true;
80-
81-
options.route = false;
82-
options.inlineTemplate = false;
83-
options.inlineStyle = false;
84-
options.prefix = null;
85-
options.spec = true;
86-
return Blueprint.load(path.join(__dirname, '../component')).install(options);
87-
}
8864
}
8965
});

tests/acceptance/generate-module.spec.js

+3-9
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,14 @@ describe('Acceptance: ng generate module', function () {
3636
return ng(['generate', 'module', 'my-module']).then(() => {
3737
expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.ts'))).to.equal(true);
3838
expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.spec.ts'))).to.equal(false);
39-
expect(existsSync(path.join(testPath, 'my-module', 'my-module.component.ts'))).to.equal(false);
4039
});
4140
});
4241

43-
it('ng generate module generate routing and component files when passed flag --routing', function () {
42+
it('ng generate module generate routing file when passed flag --routing', function () {
4443
return ng(['generate', 'module', 'my-module', '--routing']).then(() => {
4544
expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.ts'))).to.equal(true);
4645
expect(existsSync(path.join(testPath, 'my-module', 'my-module-routing.module.ts'))).to.equal(true);
4746
expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.spec.ts'))).to.equal(false);
48-
expect(existsSync(path.join(testPath, 'my-module', 'my-module.component.ts'))).to.equal(true);
4947
})
5048
});
5149

@@ -68,7 +66,6 @@ describe('Acceptance: ng generate module', function () {
6866
ng(['generate', 'module', 'parent/child']).then(() => {
6967
expect(existsSync(path.join(testPath, 'parent/child', 'child.module.ts'))).to.equal(true);
7068
expect(existsSync(path.join(testPath, 'parent/child', 'child.module.spec.ts'))).to.equal(false);
71-
expect(existsSync(path.join(testPath, 'parent/child', 'child.component.ts'))).to.equal(false);
7269
})
7370
);
7471
});
@@ -82,12 +79,11 @@ describe('Acceptance: ng generate module', function () {
8279
ng(['generate', 'module', 'child']).then(() => {
8380
expect(existsSync(path.join(testPath, 'sub-dir/child', 'child.module.ts'))).to.equal(true);
8481
expect(existsSync(path.join(testPath, 'sub-dir/child', 'child.module.spec.ts'))).to.equal(false);
85-
expect(existsSync(path.join(testPath, 'sub-dir/child', 'child.component.ts'))).to.equal(false);
8682
})
8783
);
8884
});
8985

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

105-
it('ng generate module should generate parent/child module with routing and component files when passed --routing flag', function () {
100+
it('ng generate module should generate parent/child module with routing file when passed --routing flag', function () {
106101
return ng(['generate', 'module', 'parent']).then(() =>
107102
ng(['generate', 'module', 'parent/child', '--routing']).then(() => {
108103
expect(existsSync(path.join(testPath, 'parent/child', 'child.module.ts'))).to.equal(true);
109104
expect(existsSync(path.join(testPath, 'parent/child', 'child-routing.module.ts'))).to.equal(true);
110105
expect(existsSync(path.join(testPath, 'parent/child', 'child.module.spec.ts'))).to.equal(false);
111-
expect(existsSync(path.join(testPath, 'parent/child', 'child.component.ts'))).to.equal(true);
112106
})
113107
);
114108
});

tests/e2e/tests/generate/module/module-basic.ts

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export default function() {
1111
.then(() => expectFileToExist(moduleDir))
1212
.then(() => expectFileToExist(join(moduleDir, 'test.module.ts')))
1313
.then(() => expectToFail(() => expectFileToExist(join(moduleDir, 'test-routing.module.ts'))))
14-
.then(() => expectToFail(() => expectFileToExist(join(moduleDir, 'test.component.ts'))))
1514
.then(() => expectToFail(() => expectFileToExist(join(moduleDir, 'test.spec.ts'))))
1615
.then(() => expectFileToMatch(join(moduleDir, 'test.module.ts'), 'TestModule'))
1716

tests/e2e/tests/generate/module/module-routing-child-folder.ts

-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ export default function () {
2020
.then(() => expectFileToExist(join(testPath, 'sub-dir/child')))
2121
.then(() => expectFileToExist(join(testPath, 'sub-dir/child', 'child.module.ts')))
2222
.then(() => expectFileToExist(join(testPath, 'sub-dir/child', 'child-routing.module.ts')))
23-
.then(() => expectFileToExist(join(testPath, 'sub-dir/child', 'child.component.ts')))
24-
.then(() => expectFileToExist(join(testPath, 'sub-dir/child', 'child.component.spec.ts')))
25-
.then(() => expectFileToExist(join(testPath, 'sub-dir/child', 'child.component.html')))
26-
.then(() => expectFileToExist(join(testPath, 'sub-dir/child', 'child.component.css')))
2723
.then(() => expectToFail(() =>
2824
expectFileToExist(join(testPath, 'sub-dir/child', 'child.spec.ts'))
2925
))

tests/e2e/tests/generate/module/module-routing.ts

-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ export default function() {
1111
.then(() => expectFileToExist(moduleDir))
1212
.then(() => expectFileToExist(join(moduleDir, 'test.module.ts')))
1313
.then(() => expectFileToExist(join(moduleDir, 'test-routing.module.ts')))
14-
.then(() => expectFileToExist(join(moduleDir, 'test.component.ts')))
15-
.then(() => expectFileToExist(join(moduleDir, 'test.component.spec.ts')))
16-
.then(() => expectFileToExist(join(moduleDir, 'test.component.html')))
17-
.then(() => expectFileToExist(join(moduleDir, 'test.component.css')))
1814
.then(() => expectToFail(() => expectFileToExist(join(moduleDir, 'test.spec.ts'))))
1915
// Try to run the unit tests.
2016
.then(() => ng('test', '--single-run'));

0 commit comments

Comments
 (0)