Skip to content

feat(@angular/cli): always use ng4 in ng new #5575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ env:
matrix:
fast_finish: true
allow_failures:
- env: NODE_SCRIPT="tests/run_e2e.js --nightly"
- env: NODE_SCRIPT="tests/run_e2e.js --ng2"
- node_js: "7"
- env: NODE_SCRIPT="tests/run_e2e.js --nightly --ng4"
include:
- node_js: "6"
os: linux
Expand All @@ -25,23 +26,20 @@ matrix:
- node_js: "6"
os: linux
env: NODE_SCRIPT="tests/run_e2e.js --glob=tests/build/**"
- node_js: "6"
os: linux
env: NODE_SCRIPT="tests/run_e2e.js --eject --glob=tests/build/**"
- node_js: "6"
os: linux
env: NODE_SCRIPT="tests/run_e2e.js --ignore=**/tests/build/**"
- node_js: "6"
os: linux
env: NODE_SCRIPT="tests/run_e2e.js --ng4 --glob=tests/build/**"
- node_js: "6"
os: linux
env: NODE_SCRIPT="tests/run_e2e.js --ng4 --ignore=**/tests/build/**"
env: NODE_SCRIPT="tests/run_e2e.js --eject --glob=tests/build/**"

# Optional builds.
- node_js: "6"
os: linux
env: NODE_SCRIPT="tests/run_e2e.js --nightly --ng4"
env: NODE_SCRIPT="tests/run_e2e.js --ng2"
- node_js: "6"
os: linux
env: NODE_SCRIPT="tests/run_e2e.js --nightly"
- node_js: "7"
os: linux
env: NODE_SCRIPT=tests/run_e2e.js
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
{<% if (ng4) { %>
{
"extends": "<%= relativeRootPath %>/tsconfig.json",
"compilerOptions": {<% } else { %>
"compilerOptions": {
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"lib": [
"es2016",
"dom"
],<% } %>
"outDir": "<%= relativeRootPath %>/out-tsc/app",
"module": "es2015",
"baseUrl": "",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
{<% if (ng4) { %>
{
"extends": "<%= relativeRootPath %>/tsconfig.json",
"compilerOptions": {<% } else { %>
"compilerOptions": {
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"es2016",
"dom"
],<% } %>
"outDir": "<%= relativeRootPath %>/out-tsc/spec",
"module": "commonjs",
"target": "es5",
Expand Down
11 changes: 1 addition & 10 deletions packages/@angular/cli/blueprints/ng/files/e2e/tsconfig.e2e.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
{<% if (ng4) { %>
{
"extends": "../tsconfig.json",
"compilerOptions": {<% } else { %>
"compilerOptions": {
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"es2016"
],<% } %>
"outDir": "../out-tsc/e2e",
"module": "commonjs",
"target": "es5",
Expand Down
20 changes: 10 additions & 10 deletions packages/@angular/cli/blueprints/ng/files/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
},
"private": true,
"dependencies": {
"@angular/common": "<%= ng4 ? '>=4.0.0-beta <5.0.0' : '^2.4.0' %>",
"@angular/compiler": "<%= ng4 ? '>=4.0.0-beta <5.0.0' : '^2.4.0' %>",
"@angular/core": "<%= ng4 ? '>=4.0.0-beta <5.0.0' : '^2.4.0' %>",
"@angular/forms": "<%= ng4 ? '>=4.0.0-beta <5.0.0' : '^2.4.0' %>",
"@angular/http": "<%= ng4 ? '>=4.0.0-beta <5.0.0' : '^2.4.0' %>",
"@angular/platform-browser": "<%= ng4 ? '>=4.0.0-beta <5.0.0' : '^2.4.0' %>",
"@angular/platform-browser-dynamic": "<%= ng4 ? '>=4.0.0-beta <5.0.0' : '^2.4.0' %>",
"@angular/router": "<%= ng4 ? '>=4.0.0-beta <5.0.0' : '^3.4.0' %>",
"@angular/common": "^4.0.0",
"@angular/compiler": "^4.0.0",
"@angular/core": "^4.0.0",
"@angular/forms": "^4.0.0",
"@angular/http": "^4.0.0",
"@angular/platform-browser": "^4.0.0",
"@angular/platform-browser-dynamic": "^4.0.0",
"@angular/router": "^4.0.0",
"core-js": "^2.4.1",
"rxjs": "^5.1.0",
"zone.js": "^0.8.4"
},
"devDependencies": {
"@angular/cli": "<%= version %>",
"@angular/compiler-cli": "<%= ng4 ? '>=4.0.0-beta <5.0.0' : '^2.4.0' %>",
"@angular/compiler-cli": "^4.0.0",
"@types/jasmine": "2.5.38",
"@types/node": "~6.0.60",
"codelyzer": "~2.0.0",
Expand All @@ -41,6 +41,6 @@
"protractor": "~5.1.0",
"ts-node": "~2.0.0",
"tslint": "~4.5.0",
"typescript": "<%= ng4 ? '~2.1.0' : '~2.0.0' %>"
"typescript": "~2.2.0"
}
}
1 change: 0 additions & 1 deletion packages/@angular/cli/blueprints/ng/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export default Blueprint.extend({
routing: options.routing,
inlineStyle: options.inlineStyle,
inlineTemplate: options.inlineTemplate,
ng4: options.ng4,
tests: this.tests
};
},
Expand Down
1 change: 0 additions & 1 deletion packages/@angular/cli/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const InitCommand: any = Command.extend({
{ name: 'dry-run', type: Boolean, default: false, aliases: ['d'] },
{ name: 'verbose', type: Boolean, default: false, aliases: ['v'] },
{ name: 'link-cli', type: Boolean, default: false, aliases: ['lc'] },
{ name: 'ng4', type: Boolean, default: false },
{ name: 'skip-install', type: Boolean, default: false, aliases: ['si'] },
{ name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] },
{ name: 'skip-tests', type: Boolean, default: false, aliases: ['st'] },
Expand Down
6 changes: 0 additions & 6 deletions packages/@angular/cli/commands/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ const NewCommand = Command.extend({
aliases: ['lc'],
description: 'Automatically link the `@angular/cli` package.'
},
{
name: 'ng4',
type: Boolean,
default: false,
description: 'Create a project with Angular 4 in the template.'
},
{
name: 'skip-install',
type: Boolean,
Expand Down
1 change: 0 additions & 1 deletion packages/@angular/cli/tasks/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ export default Task.extend({
inlineStyle: commandOptions.inlineStyle,
inlineTemplate: commandOptions.inlineTemplate,
ignoredUpdateFiles: ['favicon.ico'],
ng4: commandOptions.ng4,
skipGit: commandOptions.skipGit,
skipTests: commandOptions.skipTests
};
Expand Down
5 changes: 3 additions & 2 deletions tests/e2e/setup/500-create-project.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {join} from 'path';
import {git, ng, silentNpm} from '../utils/process';
import {expectFileToExist} from '../utils/fs';
import {updateTsConfig, updateJsonFile} from '../utils/project';
import {updateTsConfig, updateJsonFile, useNg2} from '../utils/project';
import {gitClean, gitCommit} from '../utils/git';
import {getGlobalVariable} from '../utils/env';

Expand All @@ -24,7 +24,7 @@ export default function() {
} else {
// Otherwise create a project from scratch.
createProject = Promise.resolve()
.then(() => ng('new', 'test-project', '--skip-install', ...(argv['ng4'] ? ['--ng4'] : [])))
.then(() => ng('new', 'test-project', '--skip-install'))
.then(() => expectFileToExist(join(process.cwd(), 'test-project')))
.then(() => process.chdir('./test-project'));
}
Expand All @@ -36,6 +36,7 @@ export default function() {
json['dependencies'][pkgName] = packages[pkgName].dist;
});
}))
.then(() => argv['ng2'] ? useNg2() : Promise.resolve())
.then(() => {
if (argv['nightly'] || argv['ng-sha']) {
const label = argv['ng-sha'] ? `#2.0.0-${argv['ng-sha']}` : '';
Expand Down
114 changes: 113 additions & 1 deletion tests/e2e/utils/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ export function createProject(name: string, ...args: string[]) {

return Promise.resolve()
.then(() => process.chdir(getGlobalVariable('tmp-root')))
.then(() => ng('new', name, '--skip-install', ...(argv['ng4'] ? ['--ng4'] : []), ...args))
.then(() => ng('new', name, '--skip-install', ...args))
.then(() => process.chdir(name))
.then(() => updateJsonFile('package.json', json => {
Object.keys(packages).forEach(pkgName => {
json['dependencies'][pkgName] = packages[pkgName].dist;
});
}))
.then(() => argv['ng2'] ? useNg2() : Promise.resolve())
.then(() => {
if (argv.nightly || argv['ng-sha']) {
const label = argv['ng-sha'] ? `#2.0.0-${argv['ng-sha']}` : '';
Expand Down Expand Up @@ -75,3 +76,114 @@ export function createProject(name: string, ...args: string[]) {
.then(() => console.log(`Project ${name} created... Installing npm.`))
.then(() => silentNpm('install'));
}

// Convert a Angular 4 project to Angular 2.
export function useNg2() {
const ng2Deps: any = {
'dependencies': {
'@angular/common': '^2.4.0',
'@angular/compiler': '^2.4.0',
'@angular/core': '^2.4.0',
'@angular/forms': '^2.4.0',
'@angular/http': '^2.4.0',
'@angular/platform-browser': '^2.4.0',
'@angular/platform-browser-dynamic': '^2.4.0',
'@angular/router': '^3.4.0',
'zone.js': '^0.7.4'
},
'devDependencies': {
'@angular/compiler-cli': '^2.4.0',
'typescript': '~2.0.0'
}
};

const tsconfigAppJson: any = {
'compilerOptions': {
'sourceMap': true,
'declaration': false,
'moduleResolution': 'node',
'emitDecoratorMetadata': true,
'experimentalDecorators': true,
'target': 'es5',
'lib': [
'es2016',
'dom'
],
'outDir': '../out-tsc/app',
'module': 'es2015',
'baseUrl': '',
'types': []
},
'exclude': [
'test.ts',
'**/*.spec.ts'
]
};

const tsconfigSpecJson: any = {
'compilerOptions': {
'sourceMap': true,
'declaration': false,
'moduleResolution': 'node',
'emitDecoratorMetadata': true,
'experimentalDecorators': true,
'lib': [
'es2016',
'dom'
],
'outDir': '../out-tsc/spec',
'module': 'commonjs',
'target': 'es5',
'baseUrl': '',
'types': [
'jasmine',
'node'
]
},
'files': [
'test.ts'
],
'include': [
'**/*.spec.ts',
'**/*.d.ts'
]
};

const tsconfigE2eJson: any = {
'compilerOptions': {
'sourceMap': true,
'declaration': false,
'moduleResolution': 'node',
'emitDecoratorMetadata': true,
'experimentalDecorators': true,
'lib': [
'es2016'
],
'outDir': '../out-tsc/e2e',
'module': 'commonjs',
'target': 'es5',
'types': [
'jasmine',
'node'
]
}
};


return Promise.resolve()
.then(() => updateJsonFile('package.json', json => {
Object.keys(ng2Deps['dependencies']).forEach(pkgName => {
json['dependencies'][pkgName] = ng2Deps['dependencies'][pkgName];
});
Object.keys(ng2Deps['devDependencies']).forEach(pkgName => {
json['devDependencies'][pkgName] = ng2Deps['devDependencies'][pkgName];
});
console.log(JSON.stringify(json))
}))
.then(() => updateJsonFile('src/tsconfig.app.json', json =>
Object.assign(json, tsconfigAppJson)))
.then(() => updateJsonFile('src/tsconfig.spec.json', json =>
Object.assign(json, tsconfigSpecJson)))
.then(() => updateJsonFile('e2e/tsconfig.e2e.json', json =>
Object.assign(json, tsconfigE2eJson)));
}