File tree Expand file tree Collapse file tree 4 files changed +41
-4
lines changed
libs/ddd/src/schematics/ui Expand file tree Collapse file tree 4 files changed +41
-4
lines changed Original file line number Diff line number Diff line change 20
20
"type" : " string" ,
21
21
"description" : " Domain name, if the library belongs to a certain domain."
22
22
},
23
+ "directory" : {
24
+ "type" : " string" ,
25
+ "description" : " Subpath of the library beneath the domain or shared folder."
26
+ },
23
27
"type" : {
24
28
"type" : " string" ,
25
29
"enum" : [
Original file line number Diff line number Diff line change @@ -18,6 +18,10 @@ export interface UiOptions {
18
18
* Domain name, if the library belongs to a certain domain.
19
19
*/
20
20
domain ?: string ;
21
+ /**
22
+ * Subpath of the library beneath the domain or shared folder.
23
+ */
24
+ directory ?: string ;
21
25
/**
22
26
* A type to determine if and how to build the library.
23
27
*/
Original file line number Diff line number Diff line change @@ -73,4 +73,33 @@ describe('ui', () => {
73
73
) ;
74
74
await expect ( schematicFunc ( ) ) . rejects . toThrowError ( ) ;
75
75
} ) ;
76
+
77
+ it ( 'should be able to customize the directory of the library within the domain / shared folder' , async ( ) => {
78
+ const tree = await runSchematic < UiOptions > (
79
+ 'ui' ,
80
+ { name : 'form-components' , domain : 'customer' , directory : 'forms' } ,
81
+ appTree
82
+ ) ;
83
+
84
+ const workspaceJson = readJsonInTree ( tree , '/workspace.json' ) ;
85
+ expect ( workspaceJson . projects ) . toHaveProperty ( 'customer-forms-ui-form-components' ) ;
86
+ expect ( workspaceJson . projects [ 'customer-forms-ui-form-components' ] . root ) . toEqual (
87
+ 'libs/customer/forms/ui-form-components'
88
+ ) ;
89
+ } ) ;
90
+
91
+ it ( 'should keep correct tags with a customized directory' , async ( ) => {
92
+ const tree = await runSchematic < UiOptions > (
93
+ 'ui' ,
94
+ { name : 'form-components' , domain : 'customer' , directory : 'forms' } ,
95
+ appTree
96
+ ) ;
97
+
98
+ const nxJson = readJsonInTree < NxJson > ( tree , '/nx.json' ) ;
99
+ expect ( nxJson . projects ) . toEqual ( {
100
+ 'customer-forms-ui-form-components' : {
101
+ tags : [ 'domain:customer' , 'type:ui' ]
102
+ }
103
+ } ) ;
104
+ } ) ;
76
105
} ) ;
Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ import { strings } from '@angular-devkit/core';
2
2
import { chain , externalSchematic , Rule } from '@angular-devkit/schematics' ;
3
3
import { UiOptions } from './schema' ;
4
4
5
-
6
5
function validateInputs ( options : UiOptions ) : void {
7
6
if ( options . shared && options . domain ) {
8
7
throw new Error ( `A UI library should either belong to a specific domain or be shared globally.
@@ -21,17 +20,18 @@ export default function(options: UiOptions): Rule {
21
20
validateInputs ( options ) ;
22
21
23
22
const libName = strings . dasherize ( options . name ) ;
24
- const libDir = options . shared ? "shared" : options . domain ;
23
+ const domain = options . shared ? 'shared' : options . domain ;
24
+ const libDir = options . directory ? `${ domain } /${ options . directory } ` : domain ;
25
25
26
26
return chain ( [
27
27
externalSchematic ( '@nrwl/angular' , 'lib' , {
28
28
name : `ui-${ libName } ` ,
29
29
directory : libDir ,
30
- tags : `domain:${ libDir } ,type:ui` ,
30
+ tags : `domain:${ domain } ,type:ui` ,
31
31
style : 'scss' ,
32
32
prefix : options . name ,
33
33
publishable : options . type === 'publishable' ,
34
- buildable : options . type === 'buildable' ,
34
+ buildable : options . type === 'buildable'
35
35
} )
36
36
] ) ;
37
37
}
You can’t perform that action at this time.
0 commit comments