diff --git a/addon/ng2/blueprints/module/files/__path__/__name__.module.ts b/addon/ng2/blueprints/module/files/__path__/__name__.module.ts index 0f5b8b702ab0..822b4c57379b 100644 --- a/addon/ng2/blueprints/module/files/__path__/__name__.module.ts +++ b/addon/ng2/blueprints/module/files/__path__/__name__.module.ts @@ -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 { } diff --git a/addon/ng2/blueprints/module/index.js b/addon/ng2/blueprints/module/index.js index 0d55885caebb..8d636dd1638b 100644 --- a/addon/ng2/blueprints/module/index.js +++ b/addon/ng2/blueprints/module/index.js @@ -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: '', @@ -10,6 +11,7 @@ module.exports = { ], normalizeEntityName: function (entityName) { + this.entityName = entityName; var parsedPath = dynamicPathParser(this.project, entityName); this.dynamicPath = parsedPath; @@ -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); } }; diff --git a/tests/acceptance/generate-module.spec.js b/tests/acceptance/generate-module.spec.js index 99aae352798e..6d376330368d 100644 --- a/tests/acceptance/generate-module.spec.js +++ b/tests/acceptance/generate-module.spec.js @@ -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); }); }); });