Skip to content

Commit 77a9f5f

Browse files
committed
feat(@angular/cli): always use ng4 in ng new
Fix #5566
1 parent 5a461f1 commit 77a9f5f

File tree

11 files changed

+136
-64
lines changed

11 files changed

+136
-64
lines changed

.travis.yml

+7-9
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ env:
1010
matrix:
1111
fast_finish: true
1212
allow_failures:
13+
- env: NODE_SCRIPT="tests/run_e2e.js --nightly"
14+
- env: NODE_SCRIPT="tests/run_e2e.js --ng2"
1315
- node_js: "7"
14-
- env: NODE_SCRIPT="tests/run_e2e.js --nightly --ng4"
1516
include:
1617
- node_js: "6"
1718
os: linux
@@ -25,23 +26,20 @@ matrix:
2526
- node_js: "6"
2627
os: linux
2728
env: NODE_SCRIPT="tests/run_e2e.js --glob=tests/build/**"
28-
- node_js: "6"
29-
os: linux
30-
env: NODE_SCRIPT="tests/run_e2e.js --eject --glob=tests/build/**"
3129
- node_js: "6"
3230
os: linux
3331
env: NODE_SCRIPT="tests/run_e2e.js --ignore=**/tests/build/**"
3432
- node_js: "6"
3533
os: linux
36-
env: NODE_SCRIPT="tests/run_e2e.js --ng4 --glob=tests/build/**"
37-
- node_js: "6"
38-
os: linux
39-
env: NODE_SCRIPT="tests/run_e2e.js --ng4 --ignore=**/tests/build/**"
34+
env: NODE_SCRIPT="tests/run_e2e.js --eject --glob=tests/build/**"
4035

4136
# Optional builds.
4237
- node_js: "6"
4338
os: linux
44-
env: NODE_SCRIPT="tests/run_e2e.js --nightly --ng4"
39+
env: NODE_SCRIPT="tests/run_e2e.js --ng2"
40+
- node_js: "6"
41+
os: linux
42+
env: NODE_SCRIPT="tests/run_e2e.js --nightly"
4543
- node_js: "7"
4644
os: linux
4745
env: NODE_SCRIPT=tests/run_e2e.js

packages/@angular/cli/blueprints/ng/files/__path__/tsconfig.app.json

+1-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
1-
{<% if (ng4) { %>
1+
{
22
"extends": "<%= relativeRootPath %>/tsconfig.json",
3-
"compilerOptions": {<% } else { %>
43
"compilerOptions": {
5-
"sourceMap": true,
6-
"declaration": false,
7-
"moduleResolution": "node",
8-
"emitDecoratorMetadata": true,
9-
"experimentalDecorators": true,
10-
"target": "es5",
11-
"lib": [
12-
"es2016",
13-
"dom"
14-
],<% } %>
154
"outDir": "<%= relativeRootPath %>/out-tsc/app",
165
"module": "es2015",
176
"baseUrl": "",

packages/@angular/cli/blueprints/ng/files/__path__/tsconfig.spec.json

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
1-
{<% if (ng4) { %>
1+
{
22
"extends": "<%= relativeRootPath %>/tsconfig.json",
3-
"compilerOptions": {<% } else { %>
43
"compilerOptions": {
5-
"sourceMap": true,
6-
"declaration": false,
7-
"moduleResolution": "node",
8-
"emitDecoratorMetadata": true,
9-
"experimentalDecorators": true,
10-
"lib": [
11-
"es2016",
12-
"dom"
13-
],<% } %>
144
"outDir": "<%= relativeRootPath %>/out-tsc/spec",
155
"module": "commonjs",
166
"target": "es5",

packages/@angular/cli/blueprints/ng/files/e2e/tsconfig.e2e.json

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
1-
{<% if (ng4) { %>
1+
{
22
"extends": "../tsconfig.json",
3-
"compilerOptions": {<% } else { %>
43
"compilerOptions": {
5-
"sourceMap": true,
6-
"declaration": false,
7-
"moduleResolution": "node",
8-
"emitDecoratorMetadata": true,
9-
"experimentalDecorators": true,
10-
"lib": [
11-
"es2016"
12-
],<% } %>
134
"outDir": "../out-tsc/e2e",
145
"module": "commonjs",
156
"target": "es5",

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

+10-10
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@
1212
},
1313
"private": true,
1414
"dependencies": {
15-
"@angular/common": "<%= ng4 ? '>=4.0.0-beta <5.0.0' : '^2.4.0' %>",
16-
"@angular/compiler": "<%= ng4 ? '>=4.0.0-beta <5.0.0' : '^2.4.0' %>",
17-
"@angular/core": "<%= ng4 ? '>=4.0.0-beta <5.0.0' : '^2.4.0' %>",
18-
"@angular/forms": "<%= ng4 ? '>=4.0.0-beta <5.0.0' : '^2.4.0' %>",
19-
"@angular/http": "<%= ng4 ? '>=4.0.0-beta <5.0.0' : '^2.4.0' %>",
20-
"@angular/platform-browser": "<%= ng4 ? '>=4.0.0-beta <5.0.0' : '^2.4.0' %>",
21-
"@angular/platform-browser-dynamic": "<%= ng4 ? '>=4.0.0-beta <5.0.0' : '^2.4.0' %>",
22-
"@angular/router": "<%= ng4 ? '>=4.0.0-beta <5.0.0' : '^3.4.0' %>",
15+
"@angular/common": "^4.0.0",
16+
"@angular/compiler": "^4.0.0",
17+
"@angular/core": "^4.0.0",
18+
"@angular/forms": "^4.0.0",
19+
"@angular/http": "^4.0.0",
20+
"@angular/platform-browser": "^4.0.0",
21+
"@angular/platform-browser-dynamic": "^4.0.0",
22+
"@angular/router": "^4.0.0",
2323
"core-js": "^2.4.1",
2424
"rxjs": "^5.1.0",
2525
"zone.js": "^0.8.4"
2626
},
2727
"devDependencies": {
2828
"@angular/cli": "<%= version %>",
29-
"@angular/compiler-cli": "<%= ng4 ? '>=4.0.0-beta <5.0.0' : '^2.4.0' %>",
29+
"@angular/compiler-cli": "^4.0.0",
3030
"@types/jasmine": "2.5.38",
3131
"@types/node": "~6.0.60",
3232
"codelyzer": "~2.0.0",
@@ -41,6 +41,6 @@
4141
"protractor": "~5.1.0",
4242
"ts-node": "~2.0.0",
4343
"tslint": "~4.5.0",
44-
"typescript": "<%= ng4 ? '~2.1.0' : '~2.0.0' %>"
44+
"typescript": "~2.1.0"
4545
}
4646
}

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

-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ export default Blueprint.extend({
5454
routing: options.routing,
5555
inlineStyle: options.inlineStyle,
5656
inlineTemplate: options.inlineTemplate,
57-
ng4: options.ng4,
5857
tests: this.tests
5958
};
6059
},

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

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const InitCommand: any = Command.extend({
99
{ name: 'dry-run', type: Boolean, default: false, aliases: ['d'] },
1010
{ name: 'verbose', type: Boolean, default: false, aliases: ['v'] },
1111
{ name: 'link-cli', type: Boolean, default: false, aliases: ['lc'] },
12-
{ name: 'ng4', type: Boolean, default: false },
1312
{ name: 'skip-install', type: Boolean, default: false, aliases: ['si'] },
1413
{ name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] },
1514
{ name: 'skip-tests', type: Boolean, default: false, aliases: ['st'] },

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

-6
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ const NewCommand = Command.extend({
4040
aliases: ['lc'],
4141
description: 'Automatically link the `@angular/cli` package.'
4242
},
43-
{
44-
name: 'ng4',
45-
type: Boolean,
46-
default: false,
47-
description: 'Create a project with Angular 4 in the template.'
48-
},
4943
{
5044
name: 'skip-install',
5145
type: Boolean,

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

-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ export default Task.extend({
7575
inlineStyle: commandOptions.inlineStyle,
7676
inlineTemplate: commandOptions.inlineTemplate,
7777
ignoredUpdateFiles: ['favicon.ico'],
78-
ng4: commandOptions.ng4,
7978
skipGit: commandOptions.skipGit,
8079
skipTests: commandOptions.skipTests
8180
};

tests/e2e/setup/500-create-project.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {join} from 'path';
22
import {git, ng, silentNpm} from '../utils/process';
33
import {expectFileToExist} from '../utils/fs';
4-
import {updateTsConfig, updateJsonFile} from '../utils/project';
4+
import {updateTsConfig, updateJsonFile, useNg2} from '../utils/project';
55
import {gitClean, gitCommit} from '../utils/git';
66
import {getGlobalVariable} from '../utils/env';
77

@@ -24,7 +24,7 @@ export default function() {
2424
} else {
2525
// Otherwise create a project from scratch.
2626
createProject = Promise.resolve()
27-
.then(() => ng('new', 'test-project', '--skip-install', ...(argv['ng4'] ? ['--ng4'] : [])))
27+
.then(() => ng('new', 'test-project', '--skip-install'))
2828
.then(() => expectFileToExist(join(process.cwd(), 'test-project')))
2929
.then(() => process.chdir('./test-project'));
3030
}
@@ -36,6 +36,7 @@ export default function() {
3636
json['dependencies'][pkgName] = packages[pkgName].dist;
3737
});
3838
}))
39+
.then(() => argv['ng2'] ? useNg2() : Promise.resolve())
3940
.then(() => {
4041
if (argv['nightly'] || argv['ng-sha']) {
4142
const label = argv['ng-sha'] ? `#2.0.0-${argv['ng-sha']}` : '';

tests/e2e/utils/project.ts

+113-1
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@ export function createProject(name: string, ...args: string[]) {
3636

3737
return Promise.resolve()
3838
.then(() => process.chdir(getGlobalVariable('tmp-root')))
39-
.then(() => ng('new', name, '--skip-install', ...(argv['ng4'] ? ['--ng4'] : []), ...args))
39+
.then(() => ng('new', name, '--skip-install', ...args))
4040
.then(() => process.chdir(name))
4141
.then(() => updateJsonFile('package.json', json => {
4242
Object.keys(packages).forEach(pkgName => {
4343
json['dependencies'][pkgName] = packages[pkgName].dist;
4444
});
4545
}))
46+
.then(() => argv['ng2'] ? useNg2() : Promise.resolve())
4647
.then(() => {
4748
if (argv.nightly || argv['ng-sha']) {
4849
const label = argv['ng-sha'] ? `#2.0.0-${argv['ng-sha']}` : '';
@@ -75,3 +76,114 @@ export function createProject(name: string, ...args: string[]) {
7576
.then(() => console.log(`Project ${name} created... Installing npm.`))
7677
.then(() => silentNpm('install'));
7778
}
79+
80+
// Convert a Angular 4 project to Angular 2.
81+
export function useNg2() {
82+
const ng2Deps: any = {
83+
'dependencies': {
84+
'@angular/common': '^2.4.0',
85+
'@angular/compiler': '^2.4.0',
86+
'@angular/core': '^2.4.0',
87+
'@angular/forms': '^2.4.0',
88+
'@angular/http': '^2.4.0',
89+
'@angular/platform-browser': '^2.4.0',
90+
'@angular/platform-browser-dynamic': '^2.4.0',
91+
'@angular/router': '^3.4.0',
92+
'zone.js': '^0.7.4'
93+
},
94+
'devDependencies': {
95+
'@angular/compiler-cli': '^2.4.0',
96+
'typescript': '~2.0.0'
97+
}
98+
};
99+
100+
const tsconfigAppJson: any = {
101+
'compilerOptions': {
102+
'sourceMap': true,
103+
'declaration': false,
104+
'moduleResolution': 'node',
105+
'emitDecoratorMetadata': true,
106+
'experimentalDecorators': true,
107+
'target': 'es5',
108+
'lib': [
109+
'es2016',
110+
'dom'
111+
],
112+
'outDir': '../out-tsc/app',
113+
'module': 'es2015',
114+
'baseUrl': '',
115+
'types': []
116+
},
117+
'exclude': [
118+
'test.ts',
119+
'**/*.spec.ts'
120+
]
121+
};
122+
123+
const tsconfigSpecJson: any = {
124+
'compilerOptions': {
125+
'sourceMap': true,
126+
'declaration': false,
127+
'moduleResolution': 'node',
128+
'emitDecoratorMetadata': true,
129+
'experimentalDecorators': true,
130+
'lib': [
131+
'es2016',
132+
'dom'
133+
],
134+
'outDir': '../out-tsc/spec',
135+
'module': 'commonjs',
136+
'target': 'es5',
137+
'baseUrl': '',
138+
'types': [
139+
'jasmine',
140+
'node'
141+
]
142+
},
143+
'files': [
144+
'test.ts'
145+
],
146+
'include': [
147+
'**/*.spec.ts',
148+
'**/*.d.ts'
149+
]
150+
};
151+
152+
const tsconfigE2eJson: any = {
153+
'compilerOptions': {
154+
'sourceMap': true,
155+
'declaration': false,
156+
'moduleResolution': 'node',
157+
'emitDecoratorMetadata': true,
158+
'experimentalDecorators': true,
159+
'lib': [
160+
'es2016'
161+
],
162+
'outDir': '../out-tsc/e2e',
163+
'module': 'commonjs',
164+
'target': 'es5',
165+
'types': [
166+
'jasmine',
167+
'node'
168+
]
169+
}
170+
};
171+
172+
173+
return Promise.resolve()
174+
.then(() => updateJsonFile('package.json', json => {
175+
Object.keys(ng2Deps['dependencies']).forEach(pkgName => {
176+
json['dependencies'][pkgName] = ng2Deps['dependencies'][pkgName];
177+
});
178+
Object.keys(ng2Deps['devDependencies']).forEach(pkgName => {
179+
json['devDependencies'][pkgName] = ng2Deps['devDependencies'][pkgName];
180+
});
181+
console.log(JSON.stringify(json))
182+
}))
183+
.then(() => updateJsonFile('src/tsconfig.app.json', json =>
184+
Object.assign(json, tsconfigAppJson)))
185+
.then(() => updateJsonFile('src/tsconfig.spec.json', json =>
186+
Object.assign(json, tsconfigSpecJson)))
187+
.then(() => updateJsonFile('e2e/tsconfig.e2e.json', json =>
188+
Object.assign(json, tsconfigE2eJson)));
189+
}

0 commit comments

Comments
 (0)