Skip to content

Commit e153205

Browse files
committed
upgrade to Angular2 2.2.0 and small fixes
1 parent 95659b1 commit e153205

File tree

14 files changed

+82
-779
lines changed

14 files changed

+82
-779
lines changed

gulpfile.js

+26-36
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,46 @@
11
var gulp = require('gulp');
2-
var ext_replace = require('gulp-ext-replace');
3-
var tslint = require('gulp-tslint');
4-
var inlineNg2Template = require('gulp-inline-ng2-template');
5-
/* CSS */
6-
var postcss = require('gulp-postcss');
7-
var sourcemaps = require('gulp-sourcemaps');
8-
var autoprefixer = require('autoprefixer');
9-
var precss = require('precss');
10-
var cssnano = require('cssnano');
11-
var typescript = require('gulp-typescript');
12-
var tsProject = typescript.createProject('tsconfig.json');
2+
var $ = require('gulp-load-plugins')({lazy: true});
3+
var sass = require('gulp-sass');
134

145
var paths = {
15-
src: {
16-
ts: './src/ts/**/*.ts',
17-
scss: './src/scss/app.scss'
18-
},
19-
dest: {
20-
js: './app/js',
21-
css: './app/css'
22-
}
6+
src: {
7+
ts: './src/ts/**/*.ts',
8+
scss: './src/scss/app.scss'
9+
},
10+
dest: {
11+
js: './app/js',
12+
css: './app/css'
13+
}
2314
};
2415

2516
gulp.task("tslint", function () {
2617
gulp.src([paths.src.ts])
27-
.pipe(tslint({
18+
.pipe($.tslint({
2819
formatter: "verbose"
2920
}))
30-
.pipe(tslint.report());
21+
.pipe($.tslint.report());
3122
});
3223

33-
gulp.task('build-ts', ["tslint", "build-css"], function () {
24+
gulp.task('build-ts', ["tslint", "build-scss"], function () {
3425
return gulp.src(paths.src.ts)
35-
.pipe(inlineNg2Template())
36-
.pipe(sourcemaps.init())
37-
.pipe(typescript(tsProject))
38-
.pipe(sourcemaps.write())
26+
.pipe($.sourcemaps.init())
27+
.pipe($.typescript.createProject('tsconfig.json', {
28+
typescript: require('typescript')
29+
})())
30+
.pipe($.sourcemaps.write())
31+
.pipe($.inlineNg2Template())
3932
.pipe(gulp.dest(paths.dest.js));
4033
});
4134

42-
gulp.task('build-css', function () {
43-
return gulp.src(paths.src.scss)
44-
.pipe(sourcemaps.init())
45-
.pipe(postcss([precss, autoprefixer, cssnano]))
46-
.pipe(sourcemaps.write())
47-
.pipe(ext_replace('.css'))
48-
.pipe(gulp.dest(paths.dest.css));
35+
gulp.task('build-scss', function () {
36+
return gulp.src(paths.src.scss)
37+
.pipe(sass().on('error', sass.logError))
38+
.pipe(gulp.dest(paths.dest.css));
4939
});
5040

5141
gulp.task('watch', function () {
52-
gulp.watch(paths.src.ts, ['build-ts']);
53-
gulp.watch(paths.src.scss, ['build-css']);
42+
gulp.watch(paths.src.ts, ['build-ts']);
43+
gulp.watch(paths.src.scss, ['build-scss']);
5444
});
5545

56-
gulp.task('default', ['watch', 'build-ts', 'build-css']);
46+
gulp.task('default', ['watch', 'build-ts', 'build-scss']);

index.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99

1010
<!-- Polyfill(s) for older browsers -->
1111
<script src="node_modules/core-js/client/shim.min.js"></script>
12-
1312
<script src="node_modules/zone.js/dist/zone.js"></script>
1413
<script src="node_modules/reflect-metadata/Reflect.js"></script>
1514
<script src="node_modules/systemjs/dist/system.src.js"></script>
1615

17-
<script src="systemjs.config.js"></script>
1816
<script>
19-
System.import('app').catch(function(err){ console.error(err); });
17+
System.import('system-config.js').then(function () {
18+
System.import('app');
19+
}).catch(console.error.bind(console));
2020
</script>
2121
</head>
2222

package.json

+20-22
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,36 @@
99
},
1010
"license": "ISC",
1111
"dependencies": {
12-
"@angular/common": "~2.1.0",
13-
"@angular/compiler": "~2.1.0",
14-
"@angular/core": "~2.1.0",
15-
"@angular/forms": "~2.1.0",
16-
"@angular/http": "~2.1.0",
17-
"@angular/platform-browser": "~2.1.0",
18-
"@angular/platform-browser-dynamic": "~2.1.0",
19-
"@angular/router": "~3.1.0",
20-
"@angular/upgrade": "~2.1.0",
21-
"es6-shim": "^0.35.0",
12+
"@angular/common": "~2.2.0",
13+
"@angular/compiler": "~2.2.0",
14+
"@angular/core": "~2.2.0",
15+
"@angular/forms": "~2.2.0",
16+
"@angular/http": "~2.2.0",
17+
"@angular/platform-browser": "~2.2.0",
18+
"@angular/platform-browser-dynamic": "~2.2.0",
19+
"@angular/router": "~3.2.0",
20+
"@angular/upgrade": "~2.2.0",
21+
22+
"systemjs": "0.19.39",
2223
"core-js": "^2.4.1",
2324
"reflect-metadata": "^0.1.8",
2425
"rxjs": "5.0.0-beta.12",
25-
"systemjs": "0.19.39",
2626
"zone.js": "^0.6.25"
2727
},
2828
"devDependencies": {
29-
"autoprefixer": "^6.3.5",
30-
"cssnano": "^3.4.0",
3129
"concurrently": "^2.0.0",
3230
"gulp": "^3.9.0",
33-
"gulp-ext-replace": "^0.2.0",
3431
"gulp-inline-ng2-template": "^4.0.0",
35-
"gulp-postcss": "^6.0.1",
36-
"gulp-sourcemaps": "^1.6.0",
32+
"gulp-load-plugins": "1.4.0",
33+
"gulp-sourcemaps": "^2.2.0",
34+
"gulp-sass": "2.3.2",
3735
"gulp-tslint": "6.1.2",
38-
"gulp-typescript": "^2.10.0",
39-
"gulp-uglify": "^1.5.1",
36+
"gulp-typescript": "^3.1.3",
4037
"lite-server": "^2.1.0",
41-
"postcss": "^5.0.13",
42-
"postcss-scss": "^0.1.3",
43-
"precss": "^1.3.0",
44-
"tslint": "^3.7.3"
38+
"tslint": "^3.7.3",
39+
"typescript": "^2.0.10",
40+
41+
"@types/core-js": "^0.9.34",
42+
"@types/node": "^6.0.46"
4543
}
4644
}
File renamed without changes.

src/html/dashboard/dashboard.component.html renamed to src/html/dashboard/dashboard.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<div>
66
<h3>Posts</h3>
77
<div class="grid grid-pad">
8-
<div *ngFor="let post of posts" (click)="gotoPost(post)" class="col-2">
8+
<div *ngFor="let post of posts" [routerLink]="['/post', post.id]" class="col-2">
99
<div class="module post">
1010
<h4>{{post.title}}</h4>
1111
<button class="delete-button" (click)="deletePost(post, $event)">X</button>
File renamed without changes.

src/ts/app-routing.module.ts

-29
This file was deleted.

src/ts/app.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {Component} from "@angular/core";
22

33
@Component({
44
selector: "my-app",
5-
templateUrl: "/src/html/app.component.html",
5+
templateUrl: "/src/html/app.html",
66
})
77
export class AppComponent {
88

src/ts/app.module.ts

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,36 @@
1-
import {AppRoutingModule, routedComponents} from "./app-routing.module";
21
import {AppComponent} from "./app.component";
2+
import {DashboardComponent} from "./dashboard/components/dashboard.component";
3+
import {PostComponent} from "./post/components/post.component";
34
import "./rxjs-extensions";
45
import {LoggingService} from "./shared/services/logging.service";
56
import {PostService} from "./shared/services/post.service";
67
import {NgModule} from "@angular/core";
78
import {FormsModule} from "@angular/forms";
89
import {HttpModule} from "@angular/http";
910
import {BrowserModule} from "@angular/platform-browser";
11+
import {RouterModule, Routes} from "@angular/router";
12+
13+
const routes: Routes = [
14+
{
15+
path: "",
16+
pathMatch: "full",
17+
redirectTo: "/dashboard",
18+
},
19+
{
20+
component: DashboardComponent,
21+
path: "dashboard",
22+
},
23+
{
24+
component: PostComponent,
25+
path: "post/:id",
26+
},
27+
];
28+
export const routedComponents = [DashboardComponent, PostComponent];
1029

1130
@NgModule({
1231
bootstrap: [AppComponent],
1332
declarations: [AppComponent, routedComponents],
14-
imports: [BrowserModule, FormsModule, HttpModule, AppRoutingModule],
33+
imports: [BrowserModule, FormsModule, HttpModule, RouterModule.forRoot(routes)],
1534
providers: [PostService, LoggingService],
1635
})
1736
export class AppModule {

src/ts/dashboard/components/dashboard.component.ts

+8-17
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import {Post} from "../../shared/models/post";
22
import {PostService} from "../../shared/services/post.service";
33
import {Component, OnDestroy, OnInit} from "@angular/core";
4-
import {Router} from "@angular/router";
54
import {Observable} from "rxjs/Observable";
65
import {AnonymousSubscription} from "rxjs/Subscription";
76

87
@Component({
98
selector: "dashboard",
10-
templateUrl: "/src/html/dashboard/dashboard.component.html",
9+
templateUrl: "/src/html/dashboard/dashboard.html",
1110
})
1211
export class DashboardComponent implements OnInit, OnDestroy {
1312

@@ -16,7 +15,7 @@ export class DashboardComponent implements OnInit, OnDestroy {
1615
private posts: Post[];
1716
private post: Post;
1817

19-
constructor(private router: Router, private postService: PostService) {
18+
constructor(private postService: PostService) {
2019
this.post = new Post();
2120
}
2221

@@ -36,25 +35,17 @@ export class DashboardComponent implements OnInit, OnDestroy {
3635
public save(): void {
3736
this.postService
3837
.save(this.post)
39-
.subscribe(bid => {
40-
this.posts.unshift(bid);
38+
.subscribe(post => {
39+
this.posts.unshift(post);
4140
this.post = new Post();
4241
});
4342
}
4443

45-
public deletePost(post: Post, event: any): void {
44+
public deletePost(postToDelete: Post, event: any): void {
4645
event.stopPropagation();
47-
this.postService
48-
.delete(post)
49-
.subscribe(() => {
50-
this.posts = this.posts.filter((returnableObjects: Post) => {
51-
return returnableObjects.id !== post.id;
52-
});
53-
});
54-
}
55-
56-
public gotoPost(post: Post): void {
57-
this.router.navigate(["/posts", post.id]);
46+
this.postService.delete(postToDelete).subscribe(() => {
47+
this.posts = this.posts.filter((post: Post) => post.id !== postToDelete.id);
48+
});
5849
}
5950

6051
private refreshData(): void {

src/ts/post/components/post.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {AnonymousSubscription} from "rxjs/Subscription";
1010
@Component({
1111
providers: [CommentService],
1212
selector: "bid",
13-
templateUrl: "src/html/post/post.component.html",
13+
templateUrl: "src/html/post/post.html",
1414
})
1515
export class PostComponent implements OnInit, OnDestroy {
1616

File renamed without changes.

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"target": "ES6",
3+
"target": "ES5",
44
"module": "system",
55
"moduleResolution": "node",
66
"sourceMap": true,

0 commit comments

Comments
 (0)