5
5
move ,
6
6
noop ,
7
7
Rule ,
8
+ SchematicContext ,
8
9
template ,
10
+ Tree ,
9
11
url ,
10
12
} from '@angular-devkit/schematics' ;
11
13
import { join , normalize } from '@angular-devkit/core' ;
@@ -21,6 +23,7 @@ import { offsetFromRoot } from '@nrwl/workspace';
21
23
import { toFileName } from '@nrwl/workspace' ;
22
24
import { Schema } from './schema' ;
23
25
import { toJS } from '@nrwl/workspace/src/utils/rules/to-js' ;
26
+ import { appsDir } from '@nrwl/workspace/src/utils/ast-utils' ;
24
27
25
28
export interface CypressProjectSchema extends Schema {
26
29
projectName : string ;
@@ -29,7 +32,6 @@ export interface CypressProjectSchema extends Schema {
29
32
30
33
function generateFiles ( options : CypressProjectSchema ) : Rule {
31
34
return ( ) : Rule => {
32
- // host.delete(`${options.projectRoot}/tsconfig.e2e.json`);
33
35
return mergeWith (
34
36
apply ( url ( './files' ) , [
35
37
template ( {
@@ -90,38 +92,47 @@ function updateWorkspaceJson(options: CypressProjectSchema): Rule {
90
92
}
91
93
92
94
export default function ( options : CypressProjectSchema ) : Rule {
93
- options = normalizeOptions ( options ) ;
94
- return chain ( [
95
- addLintFiles ( options . projectRoot , options . linter , {
96
- localConfig : {
97
- // we need this overrides because we enabled
98
- // allowJS in the tsconfig to allow for JS based
99
- // Cypress tests. That however leads to issues
100
- // with the CommonJS Cypress plugin file
101
- overrides : [
102
- {
103
- files : [ 'src/plugins/index.js' ] ,
104
- rules : {
105
- '@typescript-eslint/no-var-requires' : 'off' ,
106
- 'no-undef' : 'off' ,
95
+ return ( host : Tree , context : SchematicContext ) => {
96
+ options = normalizeOptions ( host , options ) ;
97
+ return chain ( [
98
+ addLintFiles ( options . projectRoot , options . linter , {
99
+ localConfig : {
100
+ // we need this overrides because we enabled
101
+ // allowJS in the tsconfig to allow for JS based
102
+ // Cypress tests. That however leads to issues
103
+ // with the CommonJS Cypress plugin file
104
+ overrides : [
105
+ {
106
+ files : [ 'src/plugins/index.js' ] ,
107
+ rules : {
108
+ '@typescript-eslint/no-var-requires' : 'off' ,
109
+ 'no-undef' : 'off' ,
110
+ } ,
107
111
} ,
108
- } ,
109
- ] ,
110
- } ,
111
- } ) ,
112
- generateFiles ( options ) ,
113
- updateWorkspaceJson ( options ) ,
114
- updateNxJson ( options ) ,
115
- ] ) ;
112
+ ] ,
113
+ } ,
114
+ } ) ,
115
+ generateFiles ( options ) ,
116
+ updateWorkspaceJson ( options ) ,
117
+ updateNxJson ( options ) ,
118
+ ] ) ( host , context ) ;
119
+ } ;
116
120
}
117
121
118
- function normalizeOptions ( options : CypressProjectSchema ) : CypressProjectSchema {
122
+ function normalizeOptions (
123
+ host : Tree ,
124
+ options : CypressProjectSchema
125
+ ) : CypressProjectSchema {
119
126
const projectName = options . directory
120
127
? toFileName ( options . directory ) + '-' + options . name
121
128
: options . name ;
122
129
const projectRoot = options . directory
123
- ? join ( normalize ( 'apps' ) , toFileName ( options . directory ) , options . name )
124
- : join ( normalize ( 'apps' ) , options . name ) ;
130
+ ? join (
131
+ normalize ( appsDir ( host ) ) ,
132
+ toFileName ( options . directory ) ,
133
+ options . name
134
+ )
135
+ : join ( normalize ( appsDir ( host ) ) , options . name ) ;
125
136
return {
126
137
...options ,
127
138
projectName,
0 commit comments