Skip to content

Commit 2570d9a

Browse files
committed
feat(ui): allow customization of the target directory
1 parent 05efac6 commit 2570d9a

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

libs/ddd/src/schematics/ui/schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
"type": "string",
2121
"description": "Domain name, if the library belongs to a certain domain."
2222
},
23+
"directory": {
24+
"type": "string",
25+
"description": "Subpath of the library beneath the domain or shared folder."
26+
},
2327
"type": {
2428
"type": "string",
2529
"enum": [

libs/ddd/src/schematics/ui/schema.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export interface UiOptions {
1818
* Domain name, if the library belongs to a certain domain.
1919
*/
2020
domain?: string;
21+
/**
22+
* Subpath of the library beneath the domain or shared folder.
23+
*/
24+
directory?: string;
2125
/**
2226
* A type to determine if and how to build the library.
2327
*/

libs/ddd/src/schematics/ui/ui.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,33 @@ describe('ui', () => {
7373
);
7474
await expect(schematicFunc()).rejects.toThrowError();
7575
});
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+
});
76105
});

libs/ddd/src/schematics/ui/ui.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { strings } from '@angular-devkit/core';
22
import { chain, externalSchematic, Rule } from '@angular-devkit/schematics';
33
import { UiOptions } from './schema';
44

5-
65
function validateInputs(options: UiOptions): void {
76
if (options.shared && options.domain) {
87
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 {
2120
validateInputs(options);
2221

2322
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;
2525

2626
return chain([
2727
externalSchematic('@nrwl/angular', 'lib', {
2828
name: `ui-${libName}`,
2929
directory: libDir,
30-
tags: `domain:${libDir},type:ui`,
30+
tags: `domain:${domain},type:ui`,
3131
style: 'scss',
3232
prefix: options.name,
3333
publishable: options.type === 'publishable',
34-
buildable: options.type === 'buildable',
34+
buildable: options.type === 'buildable'
3535
})
3636
]);
3737
}

0 commit comments

Comments
 (0)