Skip to content

Commit

Permalink
feat(module): add ability to generate a routing file for new modules (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Brocco committed Sep 9, 2016
1 parent 43200c4 commit 9ddba69
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 8 deletions.
6 changes: 4 additions & 2 deletions 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: []
})
Expand Down
10 changes: 10 additions & 0 deletions 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 { }
9 changes: 7 additions & 2 deletions addon/ng2/blueprints/module/index.js
Expand Up @@ -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) {
Expand All @@ -21,7 +22,8 @@ module.exports = {
locals: function (options) {
return {
dynamicPath: this.dynamicPath.dir,
spec: options.spec
spec: options.spec,
routing: options.routing
};
},

Expand All @@ -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;
},
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/tests/generate/component.ts
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/tests/generate/interface.ts
Expand Up @@ -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))
Expand Down
21 changes: 21 additions & 0 deletions 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'));
}
20 changes: 20 additions & 0 deletions 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'));
}
2 changes: 1 addition & 1 deletion tests/e2e/tests/generate/pipe.ts
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/tests/generate/service.ts
Expand Up @@ -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))
Expand Down

0 comments on commit 9ddba69

Please sign in to comment.