mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-18 03:23:57 +08:00
feat(@schematics/angular): enable routing by default for new applications
This commits updates the `routing` option in the `ng new` and `ng generation application` schematics to `true` by default and also removed the `Would you like to add Angular routing?` prompt. BREAKING CHANGE: Routing is enabled by default for new applications when using `ng generate application` and `ng new`. The `--no-routing` command line option can be used to disable this behaviour.
This commit is contained in:
parent
b3b478798e
commit
1a6a139aaf
@ -31,7 +31,6 @@ describe('Application Schematic', () => {
|
|||||||
|
|
||||||
const defaultOptions: ApplicationOptions = {
|
const defaultOptions: ApplicationOptions = {
|
||||||
name: 'foo',
|
name: 'foo',
|
||||||
routing: false,
|
|
||||||
skipPackageJson: false,
|
skipPackageJson: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -566,8 +565,8 @@ describe('Application Schematic', () => {
|
|||||||
expect(component).toMatch(/standalone: true/);
|
expect(component).toMatch(/standalone: true/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create routing information when routing is true', async () => {
|
it('should create routing information by default', async () => {
|
||||||
const options = { ...defaultOptions, standalone: true, routing: true };
|
const options = { ...defaultOptions, standalone: true };
|
||||||
|
|
||||||
const tree = await schematicRunner.runSchematic('application', options, workspaceTree);
|
const tree = await schematicRunner.runSchematic('application', options, workspaceTree);
|
||||||
|
|
||||||
|
@ -39,9 +39,8 @@
|
|||||||
},
|
},
|
||||||
"routing": {
|
"routing": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"description": "Create a routing NgModule.",
|
"description": "Creates an application with routing enabled.",
|
||||||
"default": false,
|
"default": true,
|
||||||
"x-prompt": "Would you like to add Angular routing?",
|
|
||||||
"x-user-analytics": "ep.ng_routing"
|
"x-user-analytics": "ep.ng_routing"
|
||||||
},
|
},
|
||||||
"prefix": {
|
"prefix": {
|
||||||
|
@ -51,6 +51,7 @@ describe('Ng New Schematic', () => {
|
|||||||
jasmine.arrayContaining([
|
jasmine.arrayContaining([
|
||||||
'/bar/tsconfig.app.json',
|
'/bar/tsconfig.app.json',
|
||||||
'/bar/src/main.ts',
|
'/bar/src/main.ts',
|
||||||
|
'/bar/src/app/app.routes.ts',
|
||||||
'/bar/src/app/app.config.ts',
|
'/bar/src/app/app.config.ts',
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
|
@ -91,7 +91,7 @@
|
|||||||
},
|
},
|
||||||
"routing": {
|
"routing": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"description": "Generate a routing module for the initial project.",
|
"description": "Enable routing in the initial project.",
|
||||||
"x-user-analytics": "ep.ng_routing"
|
"x-user-analytics": "ep.ng_routing"
|
||||||
},
|
},
|
||||||
"prefix": {
|
"prefix": {
|
||||||
|
@ -31,6 +31,7 @@ describe('standalone utilities', () => {
|
|||||||
{
|
{
|
||||||
name: projectName,
|
name: projectName,
|
||||||
standalone,
|
standalone,
|
||||||
|
routing: false,
|
||||||
},
|
},
|
||||||
host,
|
host,
|
||||||
);
|
);
|
||||||
|
@ -58,6 +58,7 @@ export default async function () {
|
|||||||
'src/app/app.module.ts': `
|
'src/app/app.module.ts': `
|
||||||
import { BrowserModule } from '@angular/platform-browser';
|
import { BrowserModule } from '@angular/platform-browser';
|
||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
|
import { RouterModule } from '@angular/router';
|
||||||
|
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
|
|
||||||
@ -66,6 +67,7 @@ export default async function () {
|
|||||||
AppComponent
|
AppComponent
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
|
RouterModule,
|
||||||
BrowserModule
|
BrowserModule
|
||||||
],
|
],
|
||||||
providers: [],
|
providers: [],
|
||||||
@ -95,7 +97,7 @@ export default async function () {
|
|||||||
'src/app/app.module.ts': `
|
'src/app/app.module.ts': `
|
||||||
import { BrowserModule } from '@angular/platform-browser';
|
import { BrowserModule } from '@angular/platform-browser';
|
||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
|
import { RouterModule } from '@angular/router';
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
@ -103,6 +105,7 @@ export default async function () {
|
|||||||
AppComponent
|
AppComponent
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
|
RouterModule,
|
||||||
BrowserModule
|
BrowserModule
|
||||||
],
|
],
|
||||||
providers: [],
|
providers: [],
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { appendToFile, prependToFile, readFile, replaceInFile, writeFile } from '../../utils/fs';
|
import { readFile, replaceInFile, writeFile } from '../../utils/fs';
|
||||||
import { ng } from '../../utils/process';
|
import { ng } from '../../utils/process';
|
||||||
import { updateJsonFile } from '../../utils/project';
|
import { updateJsonFile } from '../../utils/project';
|
||||||
|
|
||||||
@ -14,30 +14,6 @@ export default async function () {
|
|||||||
const projectName = 'test-project';
|
const projectName = 'test-project';
|
||||||
const appRoutingModulePath = 'src/app/app-routing.module.ts';
|
const appRoutingModulePath = 'src/app/app-routing.module.ts';
|
||||||
|
|
||||||
// Add app routing.
|
|
||||||
// This is done automatically on a new app with --routing.
|
|
||||||
await writeFile(
|
|
||||||
appRoutingModulePath,
|
|
||||||
`
|
|
||||||
import { NgModule } from '@angular/core';
|
|
||||||
import { Routes, RouterModule } from '@angular/router';
|
|
||||||
|
|
||||||
const routes: Routes = [];
|
|
||||||
|
|
||||||
@NgModule({
|
|
||||||
imports: [RouterModule.forRoot(routes)],
|
|
||||||
exports: [RouterModule]
|
|
||||||
})
|
|
||||||
export class AppRoutingModule { }
|
|
||||||
`,
|
|
||||||
);
|
|
||||||
await prependToFile(
|
|
||||||
'src/app/app.module.ts',
|
|
||||||
`import { AppRoutingModule } from './app-routing.module';`,
|
|
||||||
);
|
|
||||||
await replaceInFile('src/app/app.module.ts', `imports: [`, `imports: [ AppRoutingModule,`);
|
|
||||||
await appendToFile('src/app/app.component.html', '<router-outlet></router-outlet>');
|
|
||||||
|
|
||||||
const originalAppRoutingModule = await readFile(appRoutingModulePath);
|
const originalAppRoutingModule = await readFile(appRoutingModulePath);
|
||||||
// helper to replace loadChildren
|
// helper to replace loadChildren
|
||||||
const replaceLoadChildren = async (route: string) => {
|
const replaceLoadChildren = async (route: string) => {
|
||||||
|
@ -25,6 +25,7 @@ export default async function () {
|
|||||||
`
|
`
|
||||||
import {NgModule} from '@angular/core';
|
import {NgModule} from '@angular/core';
|
||||||
import {BrowserModule} from '@angular/platform-browser';
|
import {BrowserModule} from '@angular/platform-browser';
|
||||||
|
import {RouterModule} from '@angular/router';
|
||||||
import {SecondaryModule} from 'mylib/secondary';
|
import {SecondaryModule} from 'mylib/secondary';
|
||||||
import {AnotherModule} from 'mylib/another';
|
import {AnotherModule} from 'mylib/another';
|
||||||
|
|
||||||
@ -35,6 +36,7 @@ export default async function () {
|
|||||||
AppComponent
|
AppComponent
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
|
RouterModule,
|
||||||
SecondaryModule,
|
SecondaryModule,
|
||||||
AnotherModule,
|
AnotherModule,
|
||||||
BrowserModule
|
BrowserModule
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
import { ng } from '../../utils/process';
|
|
||||||
import { expectFileToExist, moveFile } from '../../utils/fs';
|
|
||||||
import { getGlobalVariable } from '../../utils/env';
|
|
||||||
import * as path from 'path';
|
|
||||||
|
|
||||||
export default function () {
|
|
||||||
const tmp = getGlobalVariable('tmp-root');
|
|
||||||
|
|
||||||
return Promise.resolve()
|
|
||||||
.then(() => moveFile('node_modules/@angular/router', path.join(tmp, '@angular-router.backup')))
|
|
||||||
.then(() => ng('build', '--configuration=development'))
|
|
||||||
.then(() => expectFileToExist('./dist/test-project/index.html'))
|
|
||||||
.then(() => moveFile(path.join(tmp, '@angular-router.backup'), 'node_modules/@angular/router'));
|
|
||||||
}
|
|
@ -45,5 +45,5 @@ export default async function () {
|
|||||||
await expectFileToMatch(`dist/test-project/${mainPath}`, bootstrapRegExp);
|
await expectFileToMatch(`dist/test-project/${mainPath}`, bootstrapRegExp);
|
||||||
|
|
||||||
// Size checks in bytes
|
// Size checks in bytes
|
||||||
verifySize(mainPath, 124000);
|
verifySize(mainPath, 210000);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user