@@ -36,13 +36,14 @@ export function createProject(name: string, ...args: string[]) {
36
36
37
37
return Promise . resolve ( )
38
38
. 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 ) )
40
40
. then ( ( ) => process . chdir ( name ) )
41
41
. then ( ( ) => updateJsonFile ( 'package.json' , json => {
42
42
Object . keys ( packages ) . forEach ( pkgName => {
43
43
json [ 'dependencies' ] [ pkgName ] = packages [ pkgName ] . dist ;
44
44
} ) ;
45
45
} ) )
46
+ . then ( ( ) => argv [ 'ng2' ] ? useNg2 ( ) : Promise . resolve ( ) )
46
47
. then ( ( ) => {
47
48
if ( argv . nightly || argv [ 'ng-sha' ] ) {
48
49
const label = argv [ 'ng-sha' ] ? `#2.0.0-${ argv [ 'ng-sha' ] } ` : '' ;
@@ -75,3 +76,114 @@ export function createProject(name: string, ...args: string[]) {
75
76
. then ( ( ) => console . log ( `Project ${ name } created... Installing npm.` ) )
76
77
. then ( ( ) => silentNpm ( 'install' ) ) ;
77
78
}
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