Skip to content

Commit 59beccc

Browse files
committed
refactor: upgrade to Angular 5.0
1 parent 5b88ded commit 59beccc

15 files changed

+1129
-885
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
- 运行 `npm start` 构建并启动本地Server
77
- 浏览器打开 http://localhost:4200 即可访问
88

9-
> 服务端渲染版本请运行 `git checkout ssr` 切换至 `ssr` 分支
9+
> 服务端渲染版本请运行 `git checkout ssr` 切换至 `ssr` 分支

e2e/app.po.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { browser, element, by } from 'protractor';
1+
import { browser, by, element } from 'protractor';
22

33
export class AngularContactsDemoPage {
44
navigateTo() {

e2e/tsconfig.e2e.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
"extends": "../tsconfig.json",
33
"compilerOptions": {
44
"outDir": "../out-tsc/e2e",
5+
"baseUrl": "./",
56
"module": "commonjs",
67
"target": "es5",
7-
"types":[
8+
"types": [
89
"jasmine",
10+
"jasminewd2",
911
"node"
1012
]
1113
}

karma.conf.js

+2-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Karma configuration file, see link for more information
2-
// https://karma-runner.github.io/0.13/config/configuration-file.html
2+
// https://karma-runner.github.io/1.0/config/configuration-file.html
33

44
module.exports = function (config) {
55
config.set({
@@ -15,25 +15,14 @@ module.exports = function (config) {
1515
client:{
1616
clearContext: false // leave Jasmine Spec Runner output visible in browser
1717
},
18-
files: [
19-
{ pattern: './src/test.ts', watched: false }
20-
],
21-
preprocessors: {
22-
'./src/test.ts': ['@angular/cli']
23-
},
24-
mime: {
25-
'text/x-typescript': ['ts','tsx']
26-
},
2718
coverageIstanbulReporter: {
2819
reports: [ 'html', 'lcovonly' ],
2920
fixWebpackSourcePaths: true
3021
},
3122
angularCli: {
3223
environment: 'dev'
3324
},
34-
reporters: config.angularCli && config.angularCli.codeCoverage
35-
? ['progress', 'coverage-istanbul']
36-
: ['progress', 'kjhtml'],
25+
reporters: ['progress', 'kjhtml'],
3726
port: 9876,
3827
colors: true,
3928
logLevel: config.LOG_INFO,

package.json

+27-24
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,38 @@
1212
},
1313
"private": true,
1414
"dependencies": {
15-
"@angular/common": "4.3.1",
16-
"@angular/compiler": "4.3.1",
17-
"@angular/core": "4.3.1",
18-
"@angular/forms": "4.3.1",
19-
"@angular/http": "4.3.1",
20-
"@angular/platform-browser": "4.3.1",
21-
"@angular/platform-browser-dynamic": "4.3.1",
22-
"@angular/router": "4.3.1",
15+
"@angular/animations": "5.0.0",
16+
"@angular/common": "5.0.0",
17+
"@angular/compiler": "5.0.0",
18+
"@angular/core": "5.0.0",
19+
"@angular/forms": "5.0.0",
20+
"@angular/http": "5.0.0",
21+
"@angular/platform-browser": "5.0.0",
22+
"@angular/platform-browser-dynamic": "5.0.0",
23+
"@angular/router": "5.0.0",
2324
"core-js": "2.4.1",
24-
"rxjs": "5.1.0",
25-
"zone.js": "0.8.4"
25+
"rxjs": "5.5.2",
26+
"zone.js": "0.8.14"
2627
},
2728
"devDependencies": {
28-
"@angular/cli": "1.3.0",
29-
"@angular/compiler-cli": "4.3.1",
30-
"@types/jasmine": "2.5.38",
29+
"@angular/cli": "1.5.0",
30+
"@angular/compiler-cli": "5.0.0",
31+
"@angular/language-service": "5.0.0",
32+
"@types/jasmine": "~2.5.53",
33+
"@types/jasminewd2": "~2.0.2",
3134
"@types/node": "~6.0.60",
32-
"codelyzer": "~2.0.0",
33-
"jasmine-core": "~2.5.2",
34-
"jasmine-spec-reporter": "~3.2.0",
35-
"karma": "~1.4.1",
36-
"karma-chrome-launcher": "~2.0.0",
35+
"codelyzer": "~3.2.0",
36+
"jasmine-core": "~2.6.2",
37+
"jasmine-spec-reporter": "~4.1.0",
38+
"karma": "~1.7.0",
39+
"karma-chrome-launcher": "~2.1.1",
3740
"karma-cli": "~1.0.1",
38-
"karma-coverage-istanbul-reporter": "^0.2.0",
41+
"karma-coverage-istanbul-reporter": "1.2.1",
3942
"karma-jasmine": "~1.1.0",
40-
"karma-jasmine-html-reporter": "^0.2.2",
41-
"protractor": "~5.1.0",
42-
"ts-node": "~2.0.0",
43-
"tslint": "~4.5.0",
44-
"typescript": "~2.2.0"
43+
"karma-jasmine-html-reporter": "0.2.2",
44+
"protractor": "~5.1.2",
45+
"ts-node": "~3.2.0",
46+
"tslint": "~5.7.0",
47+
"typescript": "~2.4.2"
4548
}
4649
}

protractor.conf.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ exports.config = {
1919
defaultTimeoutInterval: 30000,
2020
print: function() {}
2121
},
22-
beforeLaunch: function() {
22+
onPrepare() {
2323
require('ts-node').register({
2424
project: 'e2e/tsconfig.e2e.json'
2525
});
26-
},
27-
onPrepare() {
2826
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
2927
}
3028
};

src/index.html

+19-22
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
1-
<!DOCTYPE html>
2-
<html>
3-
<head>
4-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
5-
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0"/>
6-
<title>通讯录</title>
7-
<base href="/">
8-
<style>
9-
html,body{width: 100%;height: 100%;}
10-
*{padding: 0;margin: 0;box-sizing: border-box;
11-
font: 14px/1.5 'Microsoft Yahei','Helvetica Neue',Tahoma,'Simsun',Arial,Helvetica,STHeiti;
12-
}
13-
li{list-style-type:none;}
14-
</style>
15-
</head>
16-
<body>
17-
18-
<app-root>
19-
Loading...
20-
</app-root>
21-
22-
</body>
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0"/>
6+
<title>通讯录</title>
7+
<base href="/">
8+
<style>
9+
html,body{width: 100%;height: 100%;}
10+
*{padding: 0;margin: 0;box-sizing: border-box;
11+
font: 14px/1.5 'Microsoft Yahei','Helvetica Neue',Tahoma,'Simsun',Arial,Helvetica,STHeiti;
12+
}
13+
li{list-style-type:none;}
14+
</style>
15+
<link rel="icon" type="image/x-icon" href="favicon.ico">
16+
</head>
17+
<body>
18+
<app-root>加载中...</app-root>
19+
</body>
2320
</html>

src/main.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
2-
import {AppModule} from './app/app.module';
1+
import { enableProdMode } from '@angular/core';
2+
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3+
4+
import { AppModule } from './app/app.module';
5+
import { environment } from './environments/environment';
6+
7+
if (environment.production) {
8+
enableProdMode();
9+
}
310

411
platformBrowserDynamic().bootstrapModule(AppModule)
5-
.catch(err => console.error(err));
12+
.catch(err => console.log(err));

src/polyfills.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,25 @@ import 'core-js/es6/date';
3131
import 'core-js/es6/array';
3232
import 'core-js/es6/regexp';
3333
import 'core-js/es6/map';
34+
import 'core-js/es6/weak-map';
3435
import 'core-js/es6/set';
3536

3637
/** IE10 and IE11 requires the following for NgClass support on SVG elements */
3738
// import 'classlist.js'; // Run `npm install --save classlist.js`.
3839

39-
/** IE10 and IE11 requires the following to support `@angular/animation`. */
40-
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
40+
/** IE10 and IE11 requires the following for the Reflect API. */
41+
// import 'core-js/es6/reflect';
4142

4243

4344
/** Evergreen browsers require these. **/
44-
import 'core-js/es6/reflect';
45+
// Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove.
4546
import 'core-js/es7/reflect';
4647

4748

48-
/** ALL Firefox browsers require the following to support `@angular/animation`. **/
49+
/**
50+
* Required to support Web Animations `@angular/platform-browser/animations`.
51+
* Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation
52+
**/
4953
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
5054

5155

@@ -66,4 +70,7 @@ import 'zone.js/dist/zone'; // Included with Angular CLI.
6670
* Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10
6771
*/
6872
// import 'intl'; // Run `npm install --save intl`.
69-
73+
/**
74+
* Need to import at least one locale-data with intl.
75+
*/
76+
// import 'intl/locale-data/jsonp/en';

src/test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import {
1313
} from '@angular/platform-browser-dynamic/testing';
1414

1515
// Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
16-
declare var __karma__: any;
17-
declare var require: any;
16+
declare const __karma__: any;
17+
declare const require: any;
1818

1919
// Prevent Karma from running prematurely.
2020
__karma__.loaded = function () {};

src/tsconfig.app.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"extends": "../tsconfig.json",
33
"compilerOptions": {
44
"outDir": "../out-tsc/app",
5+
"baseUrl": "./",
56
"module": "es2015",
6-
"baseUrl": "",
77
"types": []
88
},
99
"exclude": [

src/tsconfig.spec.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"extends": "../tsconfig.json",
33
"compilerOptions": {
44
"outDir": "../out-tsc/spec",
5+
"baseUrl": "./",
56
"module": "commonjs",
67
"target": "es5",
7-
"baseUrl": "",
88
"types": [
99
"jasmine",
1010
"node"

tsconfig.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"compileOnSave": false,
33
"compilerOptions": {
44
"outDir": "./dist/out-tsc",
5-
"baseUrl": "src",
65
"sourceMap": true,
76
"declaration": false,
87
"moduleResolution": "node",
@@ -13,7 +12,7 @@
1312
"node_modules/@types"
1413
],
1514
"lib": [
16-
"es2016",
15+
"es2017",
1716
"dom"
1817
]
1918
}

tslint.json

+35-10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"node_modules/codelyzer"
44
],
55
"rules": {
6+
"arrow-return-shorthand": true,
67
"callable-types": true,
78
"class-name": true,
89
"comment-format": [
@@ -12,7 +13,11 @@
1213
"curly": true,
1314
"eofline": true,
1415
"forin": true,
15-
"import-blacklist": [true, "rxjs"],
16+
"import-blacklist": [
17+
true,
18+
"rxjs",
19+
"rxjs/Rx"
20+
],
1621
"import-spacing": true,
1722
"indent": [
1823
true,
@@ -27,8 +32,14 @@
2732
"member-access": false,
2833
"member-ordering": [
2934
true,
30-
"static-before-instance",
31-
"variables-before-functions"
35+
{
36+
"order": [
37+
"static-field",
38+
"instance-field",
39+
"static-method",
40+
"instance-method"
41+
]
42+
}
3243
],
3344
"no-arg": true,
3445
"no-bitwise": true,
@@ -42,16 +53,22 @@
4253
],
4354
"no-construct": true,
4455
"no-debugger": true,
45-
"no-duplicate-variable": true,
56+
"no-duplicate-super": true,
4657
"no-empty": false,
4758
"no-empty-interface": true,
4859
"no-eval": true,
49-
"no-inferrable-types": [true, "ignore-params"],
60+
"no-inferrable-types": [
61+
true,
62+
"ignore-params"
63+
],
64+
"no-misused-new": true,
65+
"no-non-null-assertion": true,
5066
"no-shadowed-variable": true,
5167
"no-string-literal": false,
5268
"no-string-throw": true,
5369
"no-switch-case-fall-through": true,
5470
"no-trailing-whitespace": true,
71+
"no-unnecessary-initializer": true,
5572
"no-unused-expression": true,
5673
"no-use-before-declare": true,
5774
"no-var-keyword": true,
@@ -70,6 +87,7 @@
7087
],
7188
"radix": true,
7289
"semicolon": [
90+
true,
7391
"always"
7492
],
7593
"triple-equals": [
@@ -97,9 +115,18 @@
97115
"check-separator",
98116
"check-type"
99117
],
100-
101-
"directive-selector": [true, "attribute", "app", "camelCase"],
102-
"component-selector": [true, "element", "app", "kebab-case"],
118+
"directive-selector": [
119+
true,
120+
"attribute",
121+
"app",
122+
"camelCase"
123+
],
124+
"component-selector": [
125+
true,
126+
"element",
127+
"app",
128+
"kebab-case"
129+
],
103130
"use-input-property-decorator": true,
104131
"use-output-property-decorator": true,
105132
"use-host-property-decorator": true,
@@ -109,8 +136,6 @@
109136
"use-pipe-transform-interface": true,
110137
"component-class-suffix": true,
111138
"directive-class-suffix": true,
112-
"no-access-missing-member": true,
113-
"templates-use-public": true,
114139
"invoke-injectable": true
115140
}
116141
}

0 commit comments

Comments
 (0)