Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(module): add ability to generate a routing file for new modules #1971

Merged
merged 1 commit into from
Sep 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions addon/ng2/blueprints/module/files/__path__/__name__.module.ts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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