@@ -9,92 +9,55 @@ import { installWorkspacePackages } from './packages';
9
9
import { execAndWaitForOutputToMatch , git , ng } from './process' ;
10
10
11
11
export function updateJsonFile ( filePath : string , fn : ( json : any ) => any | void ) {
12
- return readFile ( filePath )
13
- . then ( tsConfigJson => {
14
- // Remove single and multiline comments
15
- const tsConfig = JSON . parse ( tsConfigJson . replace ( / \/ \* \s ( .| \n | \r ) * \s \* \/ | \/ \/ .* / g, '' ) ) ;
16
- const result = fn ( tsConfig ) || tsConfig ;
12
+ return readFile ( filePath ) . then ( ( tsConfigJson ) => {
13
+ // Remove single and multiline comments
14
+ const tsConfig = JSON . parse ( tsConfigJson . replace ( / \/ \* \s ( .| \n | \r ) * \s \* \/ | \/ \/ .* / g, '' ) ) ;
15
+ const result = fn ( tsConfig ) || tsConfig ;
17
16
18
- return writeFile ( filePath , JSON . stringify ( result , null , 2 ) ) ;
19
- } ) ;
17
+ return writeFile ( filePath , JSON . stringify ( result , null , 2 ) ) ;
18
+ } ) ;
20
19
}
21
20
22
-
23
21
export function updateTsConfig ( fn : ( json : any ) => any | void ) {
24
22
return updateJsonFile ( 'tsconfig.json' , fn ) ;
25
23
}
26
24
27
-
28
25
export function ngServe ( ...args : string [ ] ) {
29
- return execAndWaitForOutputToMatch ( 'ng' ,
30
- [ 'serve' , ...args ] ,
31
- / C o m p i l e d s u c c e s s f u l l y ./ ) ;
26
+ return execAndWaitForOutputToMatch ( 'ng' , [ 'serve' , ...args ] , / C o m p i l e d s u c c e s s f u l l y ./ ) ;
32
27
}
33
28
34
29
export async function prepareProjectForE2e ( name ) {
35
30
const argv : string [ ] = getGlobalVariable ( 'argv' ) ;
36
31
37
- await git (
38
- 'config' ,
39
- 'user.email' ,
40
-
41
- ) ;
42
- await git (
43
- 'config' ,
44
- 'user.name' ,
45
- 'Angular CLI E2e' ,
46
- ) ;
47
- await git (
48
- 'config' ,
49
- 'commit.gpgSign' ,
50
- 'false' ,
51
- ) ;
32
+ await git ( 'config' , 'user.email' , '[email protected] ' ) ;
33
+ await git ( 'config' , 'user.name' , 'Angular CLI E2e' ) ;
34
+ await git ( 'config' , 'commit.gpgSign' , 'false' ) ;
52
35
53
36
await ng ( 'generate' , '@schematics/angular:e2e' , '--related-app-name' , name ) ;
54
37
55
- await useCIChrome (
56
- 'e2e' ,
57
- ) ;
58
- await useCIChrome (
59
- '' ,
60
- ) ;
38
+ await useCIChrome ( 'e2e' ) ;
39
+ await useCIChrome ( '' ) ;
61
40
62
41
// legacy projects
63
- await useCIChrome (
64
- 'src' ,
65
- ) ;
42
+ await useCIChrome ( 'src' ) ;
66
43
67
44
if ( argv [ 'ng-snapshots' ] || argv [ 'ng-tag' ] ) {
68
45
await useSha ( ) ;
69
46
}
70
47
71
- console . log (
72
- `Project ${ name } created... Installing npm.` ,
73
- ) ;
48
+ console . log ( `Project ${ name } created... Installing npm.` ) ;
74
49
await installWorkspacePackages ( ) ;
75
- await useCIDefaults (
76
- name ,
77
- ) ;
50
+ await useCIDefaults ( name ) ;
78
51
// Force sourcemaps to be from the root of the filesystem.
79
- await updateJsonFile (
80
- 'tsconfig.json' ,
81
- json => {
82
- json [
83
- 'compilerOptions'
84
- ] [
85
- 'sourceRoot'
86
- ] =
87
- '/' ;
88
- } ,
89
- ) ;
90
- await gitCommit (
91
- 'prepare-project-for-e2e' ,
92
- ) ;
52
+ await updateJsonFile ( 'tsconfig.json' , ( json ) => {
53
+ json [ 'compilerOptions' ] [ 'sourceRoot' ] = '/' ;
54
+ } ) ;
55
+ await gitCommit ( 'prepare-project-for-e2e' ) ;
93
56
}
94
57
95
58
export function useBuiltPackages ( ) {
96
- return Promise . resolve ( )
97
- . then ( ( ) => updateJsonFile ( 'package.json' , json => {
59
+ return Promise . resolve ( ) . then ( ( ) =>
60
+ updateJsonFile ( 'package.json' , ( json ) => {
98
61
if ( ! json [ 'dependencies' ] ) {
99
62
json [ 'dependencies' ] = { } ;
100
63
}
@@ -103,14 +66,14 @@ export function useBuiltPackages() {
103
66
}
104
67
105
68
for ( const packageName of Object . keys ( packages ) ) {
106
- if ( json [ 'dependencies' ] . hasOwnProperty ( packageName )
107
- ) {
69
+ if ( json [ 'dependencies' ] . hasOwnProperty ( packageName ) ) {
108
70
json [ 'dependencies' ] [ packageName ] = packages [ packageName ] . tar ;
109
71
} else if ( json [ 'devDependencies' ] . hasOwnProperty ( packageName ) ) {
110
72
json [ 'devDependencies' ] [ packageName ] = packages [ packageName ] . tar ;
111
73
}
112
74
}
113
- } ) ) ;
75
+ } ) ,
76
+ ) ;
114
77
}
115
78
116
79
export function useSha ( ) {
@@ -121,20 +84,19 @@ export function useSha() {
121
84
// 6.1.6+4a8d56a
122
85
const label = argv [ 'ng-tag' ] ? argv [ 'ng-tag' ] : '' ;
123
86
const ngSnapshotVersions = require ( '../ng-snapshot/package.json' ) ;
124
- return updateJsonFile ( 'package.json' , json => {
87
+ return updateJsonFile ( 'package.json' , ( json ) => {
125
88
// Install over the project with snapshot builds.
126
89
function replaceDependencies ( key : string ) {
127
90
const missingSnapshots = [ ] ;
128
91
Object . keys ( json [ key ] || { } )
129
- . filter ( name => name . match ( / ^ @ a n g u l a r \/ / ) )
130
- . forEach ( name => {
92
+ . filter ( ( name ) => name . match ( / ^ @ a n g u l a r \/ / ) )
93
+ . forEach ( ( name ) => {
131
94
const pkgName = name . split ( / \/ / ) [ 1 ] ;
132
95
if ( pkgName == 'cli' ) {
133
96
return ;
134
97
}
135
98
if ( label ) {
136
- json [ key ] [ `@angular/${ pkgName } ` ]
137
- = `github:angular/${ pkgName } -builds${ label } ` ;
99
+ json [ key ] [ `@angular/${ pkgName } ` ] = `github:angular/${ pkgName } -builds${ label } ` ;
138
100
} else {
139
101
const replacement = ngSnapshotVersions . dependencies [ `@angular/${ pkgName } ` ] ;
140
102
if ( ! replacement ) {
@@ -144,8 +106,11 @@ export function useSha() {
144
106
}
145
107
} ) ;
146
108
if ( missingSnapshots . length > 0 ) {
147
- throw new Error ( 'e2e test with --ng-snapshots requires all angular packages be ' +
148
- 'listed in tests/legacy-cli/e2e/ng-snapshot/package.json.\nErrors:\n' + missingSnapshots . join ( '\n ' ) ) ;
109
+ throw new Error (
110
+ 'e2e test with --ng-snapshots requires all angular packages be ' +
111
+ 'listed in tests/legacy-cli/e2e/ng-snapshot/package.json.\nErrors:\n' +
112
+ missingSnapshots . join ( '\n ' ) ,
113
+ ) ;
149
114
}
150
115
}
151
116
try {
@@ -161,11 +126,11 @@ export function useSha() {
161
126
}
162
127
163
128
export function useNgVersion ( version : string ) {
164
- return updateJsonFile ( 'package.json' , json => {
129
+ return updateJsonFile ( 'package.json' , ( json ) => {
165
130
// Install over the project with specific versions.
166
131
Object . keys ( json [ 'dependencies' ] || { } )
167
- . filter ( name => name . match ( / ^ @ a n g u l a r \/ / ) )
168
- . forEach ( name => {
132
+ . filter ( ( name ) => name . match ( / ^ @ a n g u l a r \/ / ) )
133
+ . forEach ( ( name ) => {
169
134
const pkgName = name . split ( / \/ / ) [ 1 ] ;
170
135
if ( pkgName == 'cli' ) {
171
136
return ;
@@ -174,8 +139,8 @@ export function useNgVersion(version: string) {
174
139
} ) ;
175
140
176
141
Object . keys ( json [ 'devDependencies' ] || { } )
177
- . filter ( name => name . match ( / ^ @ a n g u l a r \/ / ) )
178
- . forEach ( name => {
142
+ . filter ( ( name ) => name . match ( / ^ @ a n g u l a r \/ / ) )
143
+ . forEach ( ( name ) => {
179
144
const pkgName = name . split ( / \/ / ) [ 1 ] ;
180
145
if ( pkgName == 'cli' ) {
181
146
return ;
@@ -201,7 +166,7 @@ export function useNgVersion(version: string) {
201
166
}
202
167
203
168
export function useCIDefaults ( projectName = 'test-project' ) {
204
- return updateJsonFile ( 'angular.json' , workspaceJson => {
169
+ return updateJsonFile ( 'angular.json' , ( workspaceJson ) => {
205
170
// Disable progress reporting on CI to reduce spam.
206
171
const project = workspaceJson . projects [ projectName ] ;
207
172
const appTargets = project . targets || project . architect ;
0 commit comments