Skip to content

Commit f8988c3

Browse files
committed
refactor(ui,util): reuse option validation code for shareable libs
1 parent f06efb4 commit f8988c3

File tree

3 files changed

+18
-27
lines changed

3 files changed

+18
-27
lines changed

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,9 @@ import {
66
Tree
77
} from '@angular-devkit/schematics';
88
import { getNpmScope } from '@nrwl/workspace';
9+
import { validateInputs } from '../utils/lib-options';
910
import { UiOptions } from './schema';
1011

11-
function validateInputs(options: UiOptions): void {
12-
if (options.shared && options.domain) {
13-
throw new Error(`A UI library should either belong to a specific domain or be shared globally.
14-
If you want to share a UI library across multiple specific domains,
15-
consider using an API library. Hence, you should not provide the shared option in combination
16-
with the domain option.`);
17-
}
18-
19-
if (!options.shared && !options.domain) {
20-
throw new Error(`A UI library should either belong to a domain or be shared globally.
21-
Please provide either of these two options: --domain / --shared`);
22-
}
23-
}
24-
2512
export default function (options: UiOptions): Rule {
2613
return (host: Tree) => {
2714
validateInputs(options);

libs/ddd/src/schematics/util/util.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,9 @@ import {
66
Tree
77
} from '@angular-devkit/schematics';
88
import { getNpmScope } from '@nrwl/workspace';
9+
import { validateInputs } from '../utils/lib-options';
910
import { UtilOptions } from './schema';
1011

11-
function validateInputs(options: UtilOptions): void {
12-
if (options.shared && options.domain) {
13-
throw new Error(`A utility library should either belong to a specific domain or be shared globally.
14-
If you want to share a utility library across multiple specific domains,
15-
consider using an API library. Hence, you should not provide the shared option in combination
16-
with the domain option.`);
17-
}
18-
19-
if (!options.shared && !options.domain) {
20-
throw new Error(`A utilti library should either belong to a domain or be shared globally.
21-
Please provide either of these two options: --domain / --shared`);
22-
}
23-
}
2412

2513
export default function (options: UtilOptions): Rule {
2614
return (host: Tree) => {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export function validateInputs(options: {
2+
domain?: string;
3+
shared?: boolean;
4+
}): void {
5+
if (options.shared && options.domain) {
6+
throw new Error(`This library type should either belong to a specific domain or be shared globally.
7+
If you want to share this library across multiple specific domains,
8+
consider using an API library. Hence, you should not provide the shared option in combination
9+
with the domain option.`);
10+
}
11+
12+
if (!options.shared && !options.domain) {
13+
throw new Error(`This library type should either belong to a domain or be shared globally.
14+
Please provide either of these two options: --domain / --shared`);
15+
}
16+
}

0 commit comments

Comments
 (0)