6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
9
- import { join , normalize } from '@angular-devkit/core' ;
10
9
import {
11
10
Rule ,
12
11
SchematicsException ,
13
- Tree ,
14
12
apply ,
15
13
applyTemplates ,
16
14
chain ,
@@ -19,14 +17,29 @@ import {
19
17
strings ,
20
18
url ,
21
19
} from '@angular-devkit/schematics' ;
22
- import { readWorkspace , writeWorkspace } from '../utility' ;
23
- import { NodeDependencyType , addPackageJsonDependency } from '../utility/dependencies' ;
20
+ import {
21
+ AngularBuilder ,
22
+ DependencyType ,
23
+ addDependency ,
24
+ updateWorkspace ,
25
+ } from '@schematics/angular/utility' ;
26
+ import { posix as path } from 'path' ;
24
27
import { JSONFile } from '../utility/json-file' ;
25
28
import { latestVersions } from '../utility/latest-versions' ;
26
- import { relativePathToWorkspaceRoot } from '../utility/paths' ;
27
- import { Builders } from '../utility/workspace-models' ;
28
29
import { Schema as E2eOptions } from './schema' ;
29
30
31
+ /**
32
+ * The list of development dependencies used by the E2E protractor-based builder.
33
+ * The versions are sourced from the latest versions `../utility/latest-versions/package.json`
34
+ * file which is automatically updated via renovate.
35
+ */
36
+ const E2E_DEV_DEPENDENCIES = Object . freeze ( [
37
+ 'protractor' ,
38
+ 'jasmine-spec-reporter' ,
39
+ 'ts-node' ,
40
+ '@types/node' ,
41
+ ] ) ;
42
+
30
43
function addScriptsToPackageJson ( ) : Rule {
31
44
return ( host ) => {
32
45
const pkgJson = new JSONFile ( host , 'package.json' ) ;
@@ -39,70 +52,49 @@ function addScriptsToPackageJson(): Rule {
39
52
}
40
53
41
54
export default function ( options : E2eOptions ) : Rule {
42
- return async ( host : Tree ) => {
43
- const appProject = options . relatedAppName ;
44
- const workspace = await readWorkspace ( host ) ;
45
- const project = workspace . projects . get ( appProject ) ;
55
+ const { relatedAppName } = options ;
56
+
57
+ return updateWorkspace ( ( workspace ) => {
58
+ const project = workspace . projects . get ( relatedAppName ) ;
59
+
46
60
if ( ! project ) {
47
- throw new SchematicsException ( `Project name "${ appProject } " doesn't not exist.` ) ;
61
+ throw new SchematicsException ( `Project name "${ relatedAppName } " doesn't not exist.` ) ;
48
62
}
49
63
50
- const root = join ( normalize ( project . root ) , 'e2e' ) ;
64
+ const e2eRootPath = path . join ( project . root , 'e2e' ) ;
51
65
52
66
project . targets . add ( {
53
67
name : 'e2e' ,
54
- builder : Builders . Protractor ,
68
+ builder : AngularBuilder . Protractor ,
55
69
defaultConfiguration : 'development' ,
56
70
options : {
57
- protractorConfig : ` ${ root } / protractor.conf.js` ,
71
+ protractorConfig : path . join ( e2eRootPath , ' protractor.conf.js' ) ,
58
72
} ,
59
73
configurations : {
60
74
production : {
61
- devServerTarget : `${ options . relatedAppName } :serve:production` ,
75
+ devServerTarget : `${ relatedAppName } :serve:production` ,
62
76
} ,
63
77
development : {
64
- devServerTarget : `${ options . relatedAppName } :serve:development` ,
78
+ devServerTarget : `${ relatedAppName } :serve:development` ,
65
79
} ,
66
80
} ,
67
81
} ) ;
68
82
69
- await writeWorkspace ( host , workspace ) ;
70
-
71
83
return chain ( [
72
84
mergeWith (
73
85
apply ( url ( './files' ) , [
74
86
applyTemplates ( {
75
87
utils : strings ,
76
88
...options ,
77
- relativePathToWorkspaceRoot : relativePathToWorkspaceRoot ( root ) ,
89
+ relativePathToWorkspaceRoot : path . relative ( path . join ( '/' , e2eRootPath ) , '/' ) ,
78
90
} ) ,
79
- move ( root ) ,
91
+ move ( e2eRootPath ) ,
80
92
] ) ,
81
93
) ,
82
- ( host ) =>
83
- [
84
- {
85
- type : NodeDependencyType . Dev ,
86
- name : 'protractor' ,
87
- version : '~7.0.0' ,
88
- } ,
89
- {
90
- type : NodeDependencyType . Dev ,
91
- name : 'jasmine-spec-reporter' ,
92
- version : '~7.0.0' ,
93
- } ,
94
- {
95
- type : NodeDependencyType . Dev ,
96
- name : 'ts-node' ,
97
- version : latestVersions [ 'ts-node' ] ,
98
- } ,
99
- {
100
- type : NodeDependencyType . Dev ,
101
- name : '@types/node' ,
102
- version : latestVersions [ '@types/node' ] ,
103
- } ,
104
- ] . forEach ( ( dep ) => addPackageJsonDependency ( host , dep ) ) ,
94
+ ...E2E_DEV_DEPENDENCIES . map ( ( name ) =>
95
+ addDependency ( name , latestVersions [ name ] , { type : DependencyType . Dev } ) ,
96
+ ) ,
105
97
addScriptsToPackageJson ( ) ,
106
98
] ) ;
107
- } ;
99
+ } ) ;
108
100
}
0 commit comments