Skip to content

Commit a9f9976

Browse files
Broccofilipesilva
authored andcommitted
chore(generate): update routing files & add --routing to ng new (#2361)
1 parent aa48c30 commit a9f9976

File tree

12 files changed

+62
-36
lines changed

12 files changed

+62
-36
lines changed

README.md

+17-16
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ Prototype of a CLI for Angular 2 applications based on the [ember-cli](http://ww
1313

1414
This project is very much still a work in progress.
1515

16-
The CLI is now in beta.
16+
The CLI is now in beta.
1717
If you wish to collaborate while the project is still young, check out [our issue list](https://github.com/angular/angular-cli/issues).
1818

1919
## Webpack update
2020

21-
We changed the build system between beta.10 and beta.14, from SystemJS to Webpack.
22-
And with it comes a lot of benefits.
21+
We changed the build system between beta.10 and beta.14, from SystemJS to Webpack.
22+
And with it comes a lot of benefits.
2323
To take advantage of these, your app built with the old beta will need to migrate.
2424

2525
You can update your `beta.10` projects to `beta.14` by following [these instructions](https://github.com/angular/angular-cli/wiki/Upgrading-from-Beta.10-to-Beta.14).
@@ -109,6 +109,7 @@ Service | `ng g service my-new-service`
109109
Class | `ng g class my-new-class`
110110
Interface | `ng g interface my-new-interface`
111111
Enum | `ng g enum my-new-enum`
112+
Module | `ng g module my-module`
112113

113114
### Generating a route
114115

@@ -126,8 +127,8 @@ The build artifacts will be stored in the `dist/` directory.
126127

127128
### Build Targets and Environment Files
128129

129-
`ng build` can specify both a build target (`--target=production` or `--target=development`) and an
130-
environment file to be used with that build (`--environment=dev` or `--environment=prod`).
130+
`ng build` can specify both a build target (`--target=production` or `--target=development`) and an
131+
environment file to be used with that build (`--environment=dev` or `--environment=prod`).
131132
By default, the development build target and environment are used.
132133

133134
The mapping used to determine which environment file is used can be found in `angular-cli.json`:
@@ -157,7 +158,7 @@ ng build
157158

158159
You can also add your own env files other than `dev` and `prod` by doing the following:
159160
- create a `src/environments/environment.NAME.ts`
160-
- add `{ "NAME": 'src/environments/environment.NAME.ts' }` to the the `apps[0].environments` object in `angular-cli.json`
161+
- add `{ "NAME": 'src/environments/environment.NAME.ts' }` to the the `apps[0].environments` object in `angular-cli.json`
161162
- use them via the `--env=NAME` flag on the build/serve commands.
162163

163164
### Base tag handling in index.html
@@ -172,7 +173,7 @@ ng build --bh /myUrl/
172173

173174
### Bundling
174175

175-
All builds make use of bundling, and using the `--prod` flag in `ng build --prod`
176+
All builds make use of bundling, and using the `--prod` flag in `ng build --prod`
176177
or `ng serve --prod` will also make use of uglifying and tree-shaking functionality.
177178

178179
### Running unit tests
@@ -290,11 +291,11 @@ source ~/.bash_profile
290291

291292
### Global styles
292293

293-
The `styles.css` file allows users to add global styles and supports
294-
[CSS imports](https://developer.mozilla.org/en/docs/Web/CSS/@import).
294+
The `styles.css` file allows users to add global styles and supports
295+
[CSS imports](https://developer.mozilla.org/en/docs/Web/CSS/@import).
295296

296-
If the project is created with the `--style=sass` option, this will be a `.sass`
297-
file instead, and the same applies to `scss/less/styl`.
297+
If the project is created with the `--style=sass` option, this will be a `.sass`
298+
file instead, and the same applies to `scss/less/styl`.
298299

299300
You can add more global styles via the `apps[0].styles` property in `angular-cli.json`.
300301

@@ -344,11 +345,11 @@ npm install @types/d3 --save-dev
344345

345346
### Global Library Installation
346347

347-
Some javascript libraries need to be added to the global scope, and loaded as if
348-
they were in a script tag. We can do this using the `apps[0].scripts` and
348+
Some javascript libraries need to be added to the global scope, and loaded as if
349+
they were in a script tag. We can do this using the `apps[0].scripts` and
349350
`apps[0].styles` properties of `angular-cli.json`.
350351

351-
As an example, to use [Boostrap 4](http://v4-alpha.getbootstrap.com/) this is
352+
As an example, to use [Boostrap 4](http://v4-alpha.getbootstrap.com/) this is
352353
what you need to do:
353354

354355
First install Bootstrap from `npm`:
@@ -375,7 +376,7 @@ Finally add the Bootstrap CSS to the `apps[0].styles` array:
375376
],
376377
```
377378

378-
Restart `ng serve` if you're running it, and Bootstrap 4 should be working on
379+
Restart `ng serve` if you're running it, and Bootstrap 4 should be working on
379380
your app.
380381

381382
### Updating angular-cli
@@ -400,7 +401,7 @@ Running `ng init` will check for changes in all the auto-generated files created
400401

401402
Carefully read the diffs for each code file, and either accept the changes or incorporate them manually after `ng init` finishes.
402403

403-
**The main cause of errors after an update is failing to incorporate these updates into your code**.
404+
**The main cause of errors after an update is failing to incorporate these updates into your code**.
404405

405406
You can find more details about changes between versions in [CHANGELOG.md](https://github.com/angular/angular-cli/blob/master/CHANGELOG.md).
406407

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
providers: []
10+
})
11+
export class <%= classifiedModuleName %>RoutingModule { }

packages/angular-cli/blueprints/module/files/__path__/__name__.module.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { NgModule } from '@angular/core';
22
import { CommonModule } from '@angular/common';<% if (routing) { %>
3-
import { <%= camelizedModuleName %>Routing } from './<%= dasherizedModuleName %>.routing';<% } %>
3+
import { <%= classifiedModuleName %>RoutingModule } from './<%= dasherizedModuleName %>-routing.module';<% } %>
44

55
@NgModule({
66
imports: [
77
CommonModule<% if (routing) { %>,
8-
<%= camelizedModuleName %>Routing<% } %>
8+
<%= classifiedModuleName %>RoutingModule<% } %>
99
],
1010
declarations: []
1111
})

packages/angular-cli/blueprints/module/files/__path__/__name__.routing.ts

-6
This file was deleted.

packages/angular-cli/blueprints/module/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module.exports = {
3434
fileList = fileList.filter(p => p.indexOf('__name__.module.spec.ts') < 0);
3535
}
3636
if (this.options && !this.options.routing) {
37-
fileList = fileList.filter(p => p.indexOf('__name__.routing.ts') < 0);
37+
fileList = fileList.filter(p => p.indexOf('__name__-routing.module.ts') < 0);
3838
}
3939

4040
return fileList;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { NgModule } from '@angular/core';
2+
import { Routes, RouterModule } from '@angular/router';
3+
4+
const routes: Routes = [];
5+
6+
@NgModule({
7+
imports: [RouterModule.forRoot(routes)],
8+
exports: [RouterModule],
9+
providers: []
10+
})
11+
export class <%= classifiedModuleName %>RoutingModule { }

packages/angular-cli/blueprints/ng2/files/__path__/app/app.module.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { BrowserModule } from '@angular/platform-browser';
22
import { NgModule } from '@angular/core';
33
import { FormsModule } from '@angular/forms';
4-
import { HttpModule } from '@angular/http';
4+
import { HttpModule } from '@angular/http';<% if (routing) { %>
5+
import { <%= classifiedModuleName %>RoutingModule } from './<%= dasherizedModuleName %>-routing.module';<% } %>
56

67
import { AppComponent } from './app.component';
78

@@ -12,7 +13,8 @@ import { AppComponent } from './app.component';
1213
imports: [
1314
BrowserModule,
1415
FormsModule,
15-
HttpModule
16+
HttpModule<% if (routing) { %>,
17+
<%= classifiedModuleName %>RoutingModule<% } %>
1618
],
1719
providers: [],
1820
bootstrap: [AppComponent]

packages/angular-cli/blueprints/ng2/index.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ module.exports = {
1010
{ name: 'source-dir', type: String, default: 'src', aliases: ['sd'] },
1111
{ name: 'prefix', type: String, default: 'app', aliases: ['p'] },
1212
{ name: 'style', type: String, default: 'css' },
13-
{ name: 'mobile', type: Boolean, default: false }
13+
{ name: 'mobile', type: Boolean, default: false },
14+
{ name: 'routing', type: Boolean, default: false }
1415
],
1516

1617
afterInstall: function (options) {
@@ -38,7 +39,8 @@ module.exports = {
3839
prefix: options.prefix,
3940
styleExt: this.styleExt,
4041
relativeRootPath: relativeRootPath,
41-
isMobile: options.mobile
42+
isMobile: options.mobile,
43+
routing: options.routing
4244
};
4345
},
4446

@@ -48,6 +50,9 @@ module.exports = {
4850
fileList = fileList.filter(p => p.indexOf('__name__.component.html') < 0);
4951
fileList = fileList.filter(p => p.indexOf('__name__.component.__styleext__') < 0);
5052
}
53+
if (this.options && !this.options.routing) {
54+
fileList = fileList.filter(p => p.indexOf('__name__-routing.module.ts') < 0);
55+
}
5156

5257
return fileList;
5358
},

packages/angular-cli/commands/init.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ const InitCommand: any = Command.extend({
2626
{ name: 'source-dir', type: String, default: 'src', aliases: ['sd'] },
2727
{ name: 'style', type: String, default: 'css' },
2828
{ name: 'prefix', type: String, default: 'app', aliases: ['p'] },
29-
{ name: 'mobile', type: Boolean, default: false }
29+
{ name: 'mobile', type: Boolean, default: false },
30+
{ name: 'routing', type: Boolean, default: false }
3031
],
3132

3233
anonymousOptions: ['<glob-pattern>'],
@@ -104,7 +105,8 @@ const InitCommand: any = Command.extend({
104105
sourceDir: commandOptions.sourceDir,
105106
style: commandOptions.style,
106107
prefix: commandOptions.prefix,
107-
mobile: commandOptions.mobile
108+
mobile: commandOptions.mobile,
109+
routing: commandOptions.routing
108110
};
109111

110112
if (!validProjectName(packageName)) {

packages/angular-cli/commands/new.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ const NewCommand = Command.extend({
2424
{ name: 'source-dir', type: String, default: 'src', aliases: ['sd'] },
2525
{ name: 'style', type: String, default: 'css' },
2626
{ name: 'prefix', type: String, default: 'app', aliases: ['p'] },
27-
{ name: 'mobile', type: Boolean, default: false }
27+
{ name: 'mobile', type: Boolean, default: false },
28+
{ name: 'routing', type: Boolean, default: false }
2829
],
2930

3031
run: function (commandOptions: any, rawArgs: string[]) {

packages/angular-cli/utilities/find-parent-module.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ export default function findParentModule(project: any, currentDir: string): stri
1111
let pathToCheck = path.join(sourceRoot, currentDir);
1212

1313
while (pathToCheck.length >= sourceRoot.length) {
14-
// let files: string[] = fs.readdirSync(pathToCheck);
15-
16-
// files = files.filter(file => file.indexOf('.module.ts') > 0);
14+
// TODO: refactor to not be based upon file name
1715
const files = fs.readdirSync(pathToCheck)
16+
.filter(fileName => !fileName.endsWith('routing.module.ts'))
1817
.filter(fileName => fileName.endsWith('.module.ts'))
1918
.filter(fileName => fs.statSync(path.join(pathToCheck, fileName)).isFile());
2019

tests/e2e/tests/generate/module/module-routing.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default function() {
99
return ng('generate', 'module', 'test-module', '--routing')
1010
.then(() => expectFileToExist(moduleDir))
1111
.then(() => expectFileToExist(join(moduleDir, 'test-module.module.ts')))
12-
.then(() => expectFileToExist(join(moduleDir, 'test-module.routing.ts')))
12+
.then(() => expectFileToExist(join(moduleDir, 'test-module-routing.module.ts')))
1313
.then(() => expectFileToExist(join(moduleDir, 'test-module.component.ts')))
1414
.then(() => expectFileToExist(join(moduleDir, 'test-module.component.spec.ts')))
1515
.then(() => expectFileToExist(join(moduleDir, 'test-module.component.html')))

0 commit comments

Comments
 (0)