Skip to content

Commit a71e082

Browse files
committed
feat(feature): add ability to generate feature modules
1 parent 8be7096 commit a71e082

File tree

4 files changed

+41
-17
lines changed

4 files changed

+41
-17
lines changed
Lines changed: 10 additions & 3 deletions
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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
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 stringUtils = require('ember-cli-string-utils');
4+
const dynamicPathParser = require('../../utilities/dynamic-path-parser');
5+
const getFiles = Blueprint.prototype.files;
46

57
module.exports = {
68
description: '',
@@ -10,6 +12,7 @@ module.exports = {
1012
],
1113

1214
normalizeEntityName: function (entityName) {
15+
this.entityName = entityName;
1316
var parsedPath = dynamicPathParser(this.project, entityName);
1417

1518
this.dynamicPath = parsedPath;
@@ -33,13 +36,27 @@ module.exports = {
3336
return fileList;
3437
},
3538

36-
fileMapTokens: function () {
39+
fileMapTokens: function (options) {
3740
// Return custom template variables here.
41+
this.dasherizedModuleName = options.dasherizedModuleName;
3842
return {
3943
__path__: () => {
40-
this.generatePath = this.dynamicPath.dir;
44+
this.generatePath = this.dynamicPath.dir
45+
+ path.sep
46+
+ options.dasherizedModuleName;
4147
return this.generatePath;
4248
}
4349
};
50+
},
51+
52+
afterInstall: function (options) {
53+
options.entity.name = this.entityName;
54+
options.flat = false;
55+
options.route = false;
56+
options.inlineTemplate = false;
57+
options.inlineStyle = false;
58+
options.prefix = true;
59+
options.spec = true;
60+
return Blueprint.load(path.join(__dirname, '../component')).install(options);
4461
}
4562
};

tests/acceptance/generate-module.spec.js

Lines changed: 8 additions & 8 deletions
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
});

tests/runner.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var glob = require('glob');
88
var path = require('path');
99

1010
var root = 'tests/{acceptance,models,e2e}';
11-
var specFiles = glob.sync(root + '/**/*.spec.*');
11+
var specFiles = glob.sync(root + '/**/*generate-module.spec*.spec.*');
1212
var mocha = new Mocha({ timeout: 5000, reporter: 'spec' });
1313

1414
process.env.CLI_ROOT = process.env.CLI_ROOT || path.resolve(__dirname, '..');

0 commit comments

Comments
 (0)