Skip to content

Commit 7f41ead

Browse files
committed
feat(module): add ability to generate a routing file for new modules
1 parent 43200c4 commit 7f41ead

File tree

5 files changed

+66
-4
lines changed

5 files changed

+66
-4
lines changed

addon/ng2/blueprints/module/files/__path__/__name__.module.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { NgModule } from '@angular/core';
2-
import { CommonModule } from '@angular/common';
2+
import { CommonModule } from '@angular/common';<% if (routing) { %>
3+
import { <%= classifiedModuleName %>RoutingModule } from './<%= dasherizedModuleName %>.routing';<% } %>
34

45
@NgModule({
56
imports: [
6-
CommonModule
7+
CommonModule<% if (routing) { %>,
8+
<%= classifiedModuleName %>RoutingModule<% } %>
79
],
810
declarations: []
911
})
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { NgModule } from '@angular/core';
2+
import { Routes, RouterModule } from '@angular/router';
3+
4+
const routes: Routes = [];
5+
6+
@NgModule({
7+
imports: [RouterModule.forChild(routes)],
8+
exports: [RouterModule],
9+
})
10+
export class <%= classifiedModuleName %>RoutingModule { }

addon/ng2/blueprints/module/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ module.exports = {
77
description: '',
88

99
availableOptions: [
10-
{ name: 'spec', type: Boolean, default: false }
10+
{ name: 'spec', type: Boolean, default: false },
11+
{ name: 'routing', type: Boolean, default: false }
1112
],
1213

1314
normalizeEntityName: function (entityName) {
@@ -21,7 +22,8 @@ module.exports = {
2122
locals: function (options) {
2223
return {
2324
dynamicPath: this.dynamicPath.dir,
24-
spec: options.spec
25+
spec: options.spec,
26+
routing: options.routing
2527
};
2628
},
2729

@@ -31,6 +33,9 @@ module.exports = {
3133
if (!this.options || !this.options.spec) {
3234
fileList = fileList.filter(p => p.indexOf('__name__.module.spec.ts') < 0);
3335
}
36+
if (this.options && !this.options.routing) {
37+
fileList = fileList.filter(p => p.indexOf('__name__.routing.ts') < 0);
38+
}
3439

3540
return fileList;
3641
},
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {join} from 'path';
2+
import {ng} from '../../../utils/process';
3+
import {expectFileToExist} from '../../../utils/fs';
4+
import {expectToFail} from '../../../utils/utils';
5+
6+
7+
export default function() {
8+
const moduleDir = join(process.cwd(), 'src', 'app', 'test-module');
9+
const componentDir = join(moduleDir, 'test-module');
10+
11+
return ng('generate', 'module', 'test-module')
12+
.then(() => expectFileToExist(moduleDir))
13+
.then(() => expectFileToExist(join(moduleDir, 'test-module.module.ts')))
14+
.then(() => expectToFail(() => expectFileToExist(join(moduleDir, 'test-module.routing.ts'))))
15+
.then(() => expectFileToExist(componentDir))
16+
.then(() => expectFileToExist(join(componentDir, 'test-component.component.ts')))
17+
.then(() => expectFileToExist(join(componentDir, 'test-component.component.spec.ts')))
18+
.then(() => expectFileToExist(join(componentDir, 'test-component.component.html')))
19+
.then(() => expectFileToExist(join(componentDir, 'test-component.component.css')))
20+
21+
// Try to run the unit tests.
22+
.then(() => ng('test', '--watch=false'));
23+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import {join} from 'path';
2+
import {ng} from '../../../utils/process';
3+
import {expectFileToExist} from '../../../utils/fs';
4+
5+
6+
export default function() {
7+
const moduleDir = join(process.cwd(), 'src', 'app', 'test-module');
8+
const componentDir = join(moduleDir, 'test-module');
9+
10+
return ng('generate', 'module', 'test-module', '--routing')
11+
.then(() => expectFileToExist(moduleDir))
12+
.then(() => expectFileToExist(join(moduleDir, 'test-module.module.ts')))
13+
.then(() => expectFileToExist(join(moduleDir, 'test-module.routing.ts')))
14+
.then(() => expectFileToExist(componentDir))
15+
.then(() => expectFileToExist(join(componentDir, 'test-component.component.ts')))
16+
.then(() => expectFileToExist(join(componentDir, 'test-component.component.spec.ts')))
17+
.then(() => expectFileToExist(join(componentDir, 'test-component.component.html')))
18+
.then(() => expectFileToExist(join(componentDir, 'test-component.component.css')))
19+
20+
// Try to run the unit tests.
21+
.then(() => ng('test', '--watch=false'));
22+
}

0 commit comments

Comments
 (0)