Skip to content

Commit 9ddba69

Browse files
authored
feat(module): add ability to generate a routing file for new modules (#1971)
1 parent 43200c4 commit 9ddba69

File tree

9 files changed

+66
-8
lines changed

9 files changed

+66
-8
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
},

tests/e2e/tests/generate/component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {expectFileToExist} from '../../utils/fs';
44

55

66
export default function() {
7-
const componentDir = join(process.cwd(), 'src', 'app', 'test-component');
7+
const componentDir = join('src', 'app', 'test-component');
88

99
return ng('generate', 'component', 'test-component')
1010
.then(() => expectFileToExist(componentDir))

tests/e2e/tests/generate/interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {expectFileToExist} from '../../utils/fs';
44

55

66
export default function() {
7-
const interfaceDir = join(process.cwd(), 'src', 'app');
7+
const interfaceDir = join('src', 'app');
88

99
return ng('generate', 'interface', 'test-interface', 'model')
1010
.then(() => expectFileToExist(interfaceDir))
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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('src', 'app', 'test-module');
9+
10+
return ng('generate', 'module', 'test-module')
11+
.then(() => expectFileToExist(moduleDir))
12+
.then(() => expectFileToExist(join(moduleDir, 'test-module.module.ts')))
13+
.then(() => expectToFail(() => expectFileToExist(join(moduleDir, 'test-module.routing.ts'))))
14+
.then(() => expectFileToExist(join(moduleDir, 'test-module.component.ts')))
15+
.then(() => expectFileToExist(join(moduleDir, 'test-module.component.spec.ts')))
16+
.then(() => expectFileToExist(join(moduleDir, 'test-module.component.html')))
17+
.then(() => expectFileToExist(join(moduleDir, 'test-module.component.css')))
18+
19+
// Try to run the unit tests.
20+
.then(() => ng('test', '--watch=false'));
21+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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('src', 'app', 'test-module');
8+
9+
return ng('generate', 'module', 'test-module', '--routing')
10+
.then(() => expectFileToExist(moduleDir))
11+
.then(() => expectFileToExist(join(moduleDir, 'test-module.module.ts')))
12+
.then(() => expectFileToExist(join(moduleDir, 'test-module.routing.ts')))
13+
.then(() => expectFileToExist(join(moduleDir, 'test-module.component.ts')))
14+
.then(() => expectFileToExist(join(moduleDir, 'test-module.component.spec.ts')))
15+
.then(() => expectFileToExist(join(moduleDir, 'test-module.component.html')))
16+
.then(() => expectFileToExist(join(moduleDir, 'test-module.component.css')))
17+
18+
// Try to run the unit tests.
19+
.then(() => ng('test', '--watch=false'));
20+
}

tests/e2e/tests/generate/pipe.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {expectFileToExist} from '../../utils/fs';
55

66
export default function() {
77
// Create the pipe in the same directory.
8-
const pipeDir = join(process.cwd(), 'src', 'app');
8+
const pipeDir = join('src', 'app');
99

1010
return ng('generate', 'pipe', 'test-pipe')
1111
.then(() => expectFileToExist(pipeDir))

tests/e2e/tests/generate/service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {expectFileToExist} from '../../utils/fs';
55

66
export default function() {
77
// Does not create a sub directory.
8-
const serviceDir = join(process.cwd(), 'src', 'app');
8+
const serviceDir = join('src', 'app');
99

1010
return ng('generate', 'service', 'test-service')
1111
.then(() => expectFileToExist(serviceDir))

0 commit comments

Comments
 (0)