Skip to content

Commit 1f4c6fe

Browse files
Broccohansl
authored andcommitted
feat(feature): add ability to generate feature modules (angular#1867)
1 parent 8be7096 commit 1f4c6fe

File tree

3 files changed

+39
-16
lines changed

3 files changed

+39
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import { NgModule } from '@angular/core';
22
import { CommonModule } from '@angular/common';
3+
import { routing } from './<%= dasherizedModuleName %>.routes';
4+
import { <%= classifiedModuleName %>Component } from './<%= dasherizedModuleName %>.component';
35

46
@NgModule({
5-
imports: [ CommonModule ],
6-
declarations: []
7+
imports: [
8+
CommonModule,
9+
routing
10+
],
11+
declarations: [
12+
<%= classifiedModuleName %>Component
13+
]
714
})
8-
export default class <%= classifiedModuleName %>Module { }
15+
export class <%= classifiedModuleName %>Module { }

addon/ng2/blueprints/module/index.js

+21-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
var dynamicPathParser = require('../../utilities/dynamic-path-parser');
2-
var Blueprint = require('ember-cli/lib/models/blueprint');
3-
var getFiles = Blueprint.prototype.files;
1+
const path = require('path');
2+
const Blueprint = require('ember-cli/lib/models/blueprint');
3+
const dynamicPathParser = require('../../utilities/dynamic-path-parser');
4+
const getFiles = Blueprint.prototype.files;
45

56
module.exports = {
67
description: '',
@@ -10,6 +11,7 @@ module.exports = {
1011
],
1112

1213
normalizeEntityName: function (entityName) {
14+
this.entityName = entityName;
1315
var parsedPath = dynamicPathParser(this.project, entityName);
1416

1517
this.dynamicPath = parsedPath;
@@ -33,13 +35,27 @@ module.exports = {
3335
return fileList;
3436
},
3537

36-
fileMapTokens: function () {
38+
fileMapTokens: function (options) {
3739
// Return custom template variables here.
40+
this.dasherizedModuleName = options.dasherizedModuleName;
3841
return {
3942
__path__: () => {
40-
this.generatePath = this.dynamicPath.dir;
43+
this.generatePath = this.dynamicPath.dir
44+
+ path.sep
45+
+ options.dasherizedModuleName;
4146
return this.generatePath;
4247
}
4348
};
49+
},
50+
51+
afterInstall: function (options) {
52+
options.entity.name = this.entityName;
53+
options.flat = false;
54+
options.route = false;
55+
options.inlineTemplate = false;
56+
options.inlineStyle = false;
57+
options.prefix = true;
58+
options.spec = true;
59+
return Blueprint.load(path.join(__dirname, '../component')).install(options);
4460
}
4561
};

tests/acceptance/generate-module.spec.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,29 @@ describe('Acceptance: ng generate module', function () {
3232

3333
it('ng generate module my-module', function () {
3434
return ng(['generate', 'module', 'my-module']).then(() => {
35-
expect(existsSync(path.join(testPath, 'my-module.module.ts'))).to.equal(true);
36-
expect(existsSync(path.join(testPath, 'my-module.module.spec.ts'))).to.equal(false);
35+
expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.ts'))).to.equal(true);
36+
expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.spec.ts'))).to.equal(false);
3737
});
3838
});
3939

4040
it('ng generate module my-module --spec', function () {
4141
return ng(['generate', 'module', 'my-module', '--spec']).then(() => {
42-
expect(existsSync(path.join(testPath, 'my-module.module.ts'))).to.equal(true);
43-
expect(existsSync(path.join(testPath, 'my-module.module.spec.ts'))).to.equal(true);
42+
expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.ts'))).to.equal(true);
43+
expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.spec.ts'))).to.equal(true);
4444
});
4545
});
4646

4747
it(`ng generate module shared${path.sep}my-module`, function () {
4848
return ng(['generate', 'module', 'shared/my-module']).then(() => {
49-
expect(existsSync(path.join(testPath, 'shared', 'my-module.module.ts'))).to.equal(true);
50-
expect(existsSync(path.join(testPath, 'shared', 'my-module.module.spec.ts'))).to.equal(false);
49+
expect(existsSync(path.join(testPath, 'shared', 'my-module', 'my-module.module.ts'))).to.equal(true);
50+
expect(existsSync(path.join(testPath, 'shared', 'my-module', 'my-module.module.spec.ts'))).to.equal(false);
5151
});
5252
});
5353

5454
it(`ng generate module shared${path.sep}my-module --spec`, function () {
5555
return ng(['generate', 'module', 'shared/my-module', '--spec']).then(() => {
56-
expect(existsSync(path.join(testPath, 'shared', 'my-module.module.ts'))).to.equal(true);
57-
expect(existsSync(path.join(testPath, 'shared', 'my-module.module.spec.ts'))).to.equal(true);
56+
expect(existsSync(path.join(testPath, 'shared', 'my-module', 'my-module.module.ts'))).to.equal(true);
57+
expect(existsSync(path.join(testPath, 'shared', 'my-module', 'my-module.module.spec.ts'))).to.equal(true);
5858
});
5959
});
6060
});

0 commit comments

Comments
 (0)