Skip to content

Commit 9803555

Browse files
committed
feat(@angular/cli): adds --animation flag to ng new
1 parent 0df3f7c commit 9803555

File tree

11 files changed

+70
-9
lines changed

11 files changed

+70
-9
lines changed

docs/documentation/new.md

+10
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ Default applications are created in a directory of the same name, with an initia
6868
</p>
6969
</details>
7070

71+
<details>
72+
<summary>animation</summary>
73+
<p>
74+
`--animation` _default value: false_
75+
</p>
76+
<p>
77+
Generate with animation support.
78+
</p>
79+
</details>
80+
7181
<details>
7282
<summary>skip-commit</summary>
7383
<p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { trigger, state, style, animate, transition } from '@angular/animations';
2+
3+
export function AppFadeInAnimationTrigger() {
4+
return trigger('appFadeInAnimation', [
5+
state('void', style({
6+
opacity: '0'
7+
})),
8+
state('*', style({
9+
opacity: '1'
10+
})),
11+
transition('void <=> *', animate('5000ms ease'))
12+
])
13+
}
14+
15+
export const AppFadeInAnimation = AppFadeInAnimationTrigger();
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<h1>
1+
<h1<% if(animation) { %> @appFadeInAnimation <% } %>>
22
{{title}}
33
</h1><% if (routing) { %>
44
<router-outlet></router-outlet><% } %>

packages/@angular/cli/blueprints/ng/files/__path__/app/app.component.spec.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
import { TestBed, async } from '@angular/core/testing';<% if (routing) { %>
2-
import { RouterTestingModule } from '@angular/router/testing';<% } %>
2+
import { RouterTestingModule } from '@angular/router/testing';<% } %><% if (animation) { %>
3+
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';<% } %>
34

45
import { AppComponent } from './app.component';
56

67
describe('AppComponent', () => {
78
beforeEach(async(() => {
8-
TestBed.configureTestingModule({<% if (routing) { %>
9+
TestBed.configureTestingModule({<% if (routing && animation) { %>
10+
imports: [
11+
RouterTestingModule,
12+
BrowserAnimationsModule
13+
],<% } %><% if (routing && !animation) { %>
914
imports: [
1015
RouterTestingModule
16+
],<% } %><% if (animation && !routing) { %>
17+
imports: [
18+
BrowserAnimationsModule
1119
],<% } %>
1220
declarations: [
1321
AppComponent

packages/@angular/cli/blueprints/ng/files/__path__/app/app.component.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
import { Component } from '@angular/core';
1+
import { Component } from '@angular/core';<% if(animation) { %>
2+
import { AppFadeInAnimation } from './app-fade-in.animation';<% } %>
23

34
@Component({
45
selector: '<%= prefix %>-root',<% if (inlineTemplate) { %>
56
template: `
6-
<h1>
7+
<h1<% if(animation) { %> @appFadeInAnimation <% } %>>
78
{{title}}
89
</h1><% if (routing) { %>
910
<router-outlet></router-outlet><% } %>
1011
`,<% } else { %>
1112
templateUrl: './app.component.html',<% } %><% if (inlineStyle) { %>
1213
styles: []<% } else { %>
13-
styleUrls: ['./app.component.<%= styleExt %>']<% } %>
14+
styleUrls: ['./app.component.<%= styleExt %>']<% } %><% if(animation) { %>,
15+
animations: [AppFadeInAnimation]<% } %>
1416
})
1517
export class AppComponent {
1618
title = '<%= prefix %> works!';

packages/@angular/cli/blueprints/ng/files/__path__/app/app.module.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { BrowserModule } from '@angular/platform-browser';
1+
import { BrowserModule } from '@angular/platform-browser';<% if (animation) { %>
2+
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';<% } %>
23
import { NgModule } from '@angular/core';
34
import { FormsModule } from '@angular/forms';
45
import { HttpModule } from '@angular/http';
@@ -11,7 +12,8 @@ import { AppComponent } from './app.component';
1112
AppComponent
1213
],
1314
imports: [
14-
BrowserModule,
15+
BrowserModule,<% if (animation) { %>
16+
BrowserAnimationsModule,<% } %>
1517
FormsModule,
1618
HttpModule<% if (routing) { %>,
1719
AppRoutingModule<% } %>

packages/@angular/cli/blueprints/ng/files/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"@angular/http": "^4.0.0",
2020
"@angular/platform-browser": "^4.0.0",
2121
"@angular/platform-browser-dynamic": "^4.0.0",
22-
"@angular/router": "^4.0.0",
22+
"@angular/router": "^4.0.0",<% if (animation) { %>
23+
"@angular/animations": "^4.0.0",<% } %>
2324
"core-js": "^2.4.1",
2425
"rxjs": "^5.1.0",
2526
"zone.js": "^0.8.4"

packages/@angular/cli/blueprints/ng/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default Blueprint.extend({
1313
{ name: 'prefix', type: String, default: 'app', aliases: ['p'] },
1414
{ name: 'style', type: String },
1515
{ name: 'routing', type: Boolean, default: false },
16+
{ name: 'animation', type: Boolean, default: false },
1617
{ name: 'inline-style', type: Boolean, default: false, aliases: ['is'] },
1718
{ name: 'inline-template', type: Boolean, default: false, aliases: ['it'] },
1819
{ name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] }
@@ -53,6 +54,7 @@ export default Blueprint.extend({
5354
styleExt: this.styleExt,
5455
relativeRootPath: relativeRootPath,
5556
routing: options.routing,
57+
animation: options.animation,
5658
inlineStyle: options.inlineStyle,
5759
inlineTemplate: options.inlineTemplate,
5860
tests: this.tests,
@@ -66,6 +68,9 @@ export default Blueprint.extend({
6668
if (this.options && !this.options.routing) {
6769
fileList = fileList.filter(p => p.indexOf('app-routing.module.ts') < 0);
6870
}
71+
if (this.options && !this.options.animation) {
72+
fileList = fileList.filter(p => p.indexOf('app-fade-in.animation.ts') < 0);
73+
}
6974
if (this.options && this.options.inlineTemplate) {
7075
fileList = fileList.filter(p => p.indexOf('app.component.html') < 0);
7176
}

packages/@angular/cli/commands/new.ts

+6
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ const NewCommand = Command.extend({
108108
default: false,
109109
description: 'Generate a routing module.'
110110
},
111+
{
112+
name: 'animation',
113+
type: Boolean,
114+
default: false,
115+
description: 'Generate with animation support.'
116+
},
111117
{
112118
name: 'inline-style',
113119
type: Boolean,

packages/@angular/cli/tasks/init.ts

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export default Task.extend({
7474
style: commandOptions.style,
7575
prefix: commandOptions.prefix.trim() || 'app',
7676
routing: commandOptions.routing,
77+
animation: commandOptions.animation,
7778
inlineStyle: commandOptions.inlineStyle,
7879
inlineTemplate: commandOptions.inlineTemplate,
7980
ignoredUpdateFiles: ['favicon.ico'],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {ng} from '../../../utils/process';
2+
import {createProject} from '../../../utils/project';
3+
4+
5+
export default function() {
6+
return Promise.resolve()
7+
.then(() => createProject('animation-project', '--animation'))
8+
9+
// Try to run the unit tests.
10+
.then(() => ng('test', '--single-run'));
11+
}

0 commit comments

Comments
 (0)