Skip to content

feat(feature): add ability to generate feature modules #1867

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
Aug 29, 2016
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
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);
});
});
});