Skip to content

Commit

Permalink
feat(feature): add ability to generate feature modules (#1867)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brocco authored and hansl committed Aug 29, 2016
1 parent 8be7096 commit 1f4c6fe
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
13 changes: 10 additions & 3 deletions addon/ng2/blueprints/module/files/__path__/__name__.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { routing } from './<%= dasherizedModuleName %>.routes';
import { <%= classifiedModuleName %>Component } from './<%= dasherizedModuleName %>.component';

@NgModule({
imports: [ CommonModule ],
declarations: []
imports: [
CommonModule,
routing
],
declarations: [
<%= classifiedModuleName %>Component
]
})
export default class <%= classifiedModuleName %>Module { }
export class <%= classifiedModuleName %>Module { }
26 changes: 21 additions & 5 deletions addon/ng2/blueprints/module/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var dynamicPathParser = require('../../utilities/dynamic-path-parser');
var Blueprint = require('ember-cli/lib/models/blueprint');
var getFiles = Blueprint.prototype.files;
const path = require('path');
const Blueprint = require('ember-cli/lib/models/blueprint');
const dynamicPathParser = require('../../utilities/dynamic-path-parser');
const getFiles = Blueprint.prototype.files;

module.exports = {
description: '',
Expand All @@ -10,6 +11,7 @@ module.exports = {
],

normalizeEntityName: function (entityName) {
this.entityName = entityName;
var parsedPath = dynamicPathParser(this.project, entityName);

this.dynamicPath = parsedPath;
Expand All @@ -33,13 +35,27 @@ module.exports = {
return fileList;
},

fileMapTokens: function () {
fileMapTokens: function (options) {
// Return custom template variables here.
this.dasherizedModuleName = options.dasherizedModuleName;
return {
__path__: () => {
this.generatePath = this.dynamicPath.dir;
this.generatePath = this.dynamicPath.dir
+ path.sep
+ options.dasherizedModuleName;
return this.generatePath;
}
};
},

afterInstall: function (options) {
options.entity.name = this.entityName;
options.flat = false;
options.route = false;
options.inlineTemplate = false;
options.inlineStyle = false;
options.prefix = true;
options.spec = true;
return Blueprint.load(path.join(__dirname, '../component')).install(options);
}
};
16 changes: 8 additions & 8 deletions tests/acceptance/generate-module.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,29 @@ describe('Acceptance: ng generate module', function () {

it('ng generate module my-module', function () {
return ng(['generate', 'module', 'my-module']).then(() => {
expect(existsSync(path.join(testPath, 'my-module.module.ts'))).to.equal(true);
expect(existsSync(path.join(testPath, 'my-module.module.spec.ts'))).to.equal(false);
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);
});
});

it('ng generate module my-module --spec', function () {
return ng(['generate', 'module', 'my-module', '--spec']).then(() => {
expect(existsSync(path.join(testPath, 'my-module.module.ts'))).to.equal(true);
expect(existsSync(path.join(testPath, 'my-module.module.spec.ts'))).to.equal(true);
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(true);
});
});

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

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

0 comments on commit 1f4c6fe

Please sign in to comment.