diff --git a/addon/ng2/blueprints/module/files/__path__/__name__.module.ts b/addon/ng2/blueprints/module/files/__path__/__name__.module.ts index dbd299520ab7..1fec838cd123 100644 --- a/addon/ng2/blueprints/module/files/__path__/__name__.module.ts +++ b/addon/ng2/blueprints/module/files/__path__/__name__.module.ts @@ -1,9 +1,11 @@ import { NgModule } from '@angular/core'; -import { CommonModule } from '@angular/common'; +import { CommonModule } from '@angular/common';<% if (routing) { %> +import { <%= classifiedModuleName %>RoutingModule } from './<%= dasherizedModuleName %>.routing';<% } %> @NgModule({ imports: [ - CommonModule + CommonModule<% if (routing) { %>, + <%= classifiedModuleName %>RoutingModule<% } %> ], declarations: [] }) diff --git a/addon/ng2/blueprints/module/files/__path__/__name__.routing.ts b/addon/ng2/blueprints/module/files/__path__/__name__.routing.ts new file mode 100644 index 000000000000..b4d4ee500356 --- /dev/null +++ b/addon/ng2/blueprints/module/files/__path__/__name__.routing.ts @@ -0,0 +1,10 @@ +import { NgModule } from '@angular/core'; +import { Routes, RouterModule } from '@angular/router'; + +const routes: Routes = []; + +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule], +}) +export class <%= classifiedModuleName %>RoutingModule { } diff --git a/addon/ng2/blueprints/module/index.js b/addon/ng2/blueprints/module/index.js index f8285ab748d7..7b2f01ff0e04 100644 --- a/addon/ng2/blueprints/module/index.js +++ b/addon/ng2/blueprints/module/index.js @@ -7,7 +7,8 @@ module.exports = { description: '', availableOptions: [ - { name: 'spec', type: Boolean, default: false } + { name: 'spec', type: Boolean, default: false }, + { name: 'routing', type: Boolean, default: false } ], normalizeEntityName: function (entityName) { @@ -21,7 +22,8 @@ module.exports = { locals: function (options) { return { dynamicPath: this.dynamicPath.dir, - spec: options.spec + spec: options.spec, + routing: options.routing }; }, @@ -31,6 +33,9 @@ module.exports = { if (!this.options || !this.options.spec) { fileList = fileList.filter(p => p.indexOf('__name__.module.spec.ts') < 0); } + if (this.options && !this.options.routing) { + fileList = fileList.filter(p => p.indexOf('__name__.routing.ts') < 0); + } return fileList; }, diff --git a/tests/e2e/tests/generate/component.ts b/tests/e2e/tests/generate/component.ts index 8819ff85c177..251c14ebcc4e 100644 --- a/tests/e2e/tests/generate/component.ts +++ b/tests/e2e/tests/generate/component.ts @@ -4,7 +4,7 @@ import {expectFileToExist} from '../../utils/fs'; export default function() { - const componentDir = join(process.cwd(), 'src', 'app', 'test-component'); + const componentDir = join('src', 'app', 'test-component'); return ng('generate', 'component', 'test-component') .then(() => expectFileToExist(componentDir)) diff --git a/tests/e2e/tests/generate/interface.ts b/tests/e2e/tests/generate/interface.ts index 1a28b0f1227c..e74f2570f4f1 100644 --- a/tests/e2e/tests/generate/interface.ts +++ b/tests/e2e/tests/generate/interface.ts @@ -4,7 +4,7 @@ import {expectFileToExist} from '../../utils/fs'; export default function() { - const interfaceDir = join(process.cwd(), 'src', 'app'); + const interfaceDir = join('src', 'app'); return ng('generate', 'interface', 'test-interface', 'model') .then(() => expectFileToExist(interfaceDir)) diff --git a/tests/e2e/tests/generate/module/module-basic.ts b/tests/e2e/tests/generate/module/module-basic.ts new file mode 100644 index 000000000000..4e7aa59b3d27 --- /dev/null +++ b/tests/e2e/tests/generate/module/module-basic.ts @@ -0,0 +1,21 @@ +import {join} from 'path'; +import {ng} from '../../../utils/process'; +import {expectFileToExist} from '../../../utils/fs'; +import {expectToFail} from '../../../utils/utils'; + + +export default function() { + const moduleDir = join('src', 'app', 'test-module'); + + return ng('generate', 'module', 'test-module') + .then(() => expectFileToExist(moduleDir)) + .then(() => expectFileToExist(join(moduleDir, 'test-module.module.ts'))) + .then(() => expectToFail(() => expectFileToExist(join(moduleDir, 'test-module.routing.ts')))) + .then(() => expectFileToExist(join(moduleDir, 'test-module.component.ts'))) + .then(() => expectFileToExist(join(moduleDir, 'test-module.component.spec.ts'))) + .then(() => expectFileToExist(join(moduleDir, 'test-module.component.html'))) + .then(() => expectFileToExist(join(moduleDir, 'test-module.component.css'))) + + // Try to run the unit tests. + .then(() => ng('test', '--watch=false')); +} diff --git a/tests/e2e/tests/generate/module/module-routing.ts b/tests/e2e/tests/generate/module/module-routing.ts new file mode 100644 index 000000000000..d339ebf01740 --- /dev/null +++ b/tests/e2e/tests/generate/module/module-routing.ts @@ -0,0 +1,20 @@ +import {join} from 'path'; +import {ng} from '../../../utils/process'; +import {expectFileToExist} from '../../../utils/fs'; + + +export default function() { + const moduleDir = join('src', 'app', 'test-module'); + + return ng('generate', 'module', 'test-module', '--routing') + .then(() => expectFileToExist(moduleDir)) + .then(() => expectFileToExist(join(moduleDir, 'test-module.module.ts'))) + .then(() => expectFileToExist(join(moduleDir, 'test-module.routing.ts'))) + .then(() => expectFileToExist(join(moduleDir, 'test-module.component.ts'))) + .then(() => expectFileToExist(join(moduleDir, 'test-module.component.spec.ts'))) + .then(() => expectFileToExist(join(moduleDir, 'test-module.component.html'))) + .then(() => expectFileToExist(join(moduleDir, 'test-module.component.css'))) + + // Try to run the unit tests. + .then(() => ng('test', '--watch=false')); +} diff --git a/tests/e2e/tests/generate/pipe.ts b/tests/e2e/tests/generate/pipe.ts index 0f848d718a13..bc0cc0f02bea 100644 --- a/tests/e2e/tests/generate/pipe.ts +++ b/tests/e2e/tests/generate/pipe.ts @@ -5,7 +5,7 @@ import {expectFileToExist} from '../../utils/fs'; export default function() { // Create the pipe in the same directory. - const pipeDir = join(process.cwd(), 'src', 'app'); + const pipeDir = join('src', 'app'); return ng('generate', 'pipe', 'test-pipe') .then(() => expectFileToExist(pipeDir)) diff --git a/tests/e2e/tests/generate/service.ts b/tests/e2e/tests/generate/service.ts index f7ff430eb6b5..938ed7bd0cf2 100644 --- a/tests/e2e/tests/generate/service.ts +++ b/tests/e2e/tests/generate/service.ts @@ -5,7 +5,7 @@ import {expectFileToExist} from '../../utils/fs'; export default function() { // Does not create a sub directory. - const serviceDir = join(process.cwd(), 'src', 'app'); + const serviceDir = join('src', 'app'); return ng('generate', 'service', 'test-service') .then(() => expectFileToExist(serviceDir))