1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | exports.validateOptionsWithSchema = exports.InvalidInputOptions = void 0;
|
11 | const core_1 = require("@angular-devkit/core");
|
12 | const rxjs_1 = require("rxjs");
|
13 | const operators_1 = require("rxjs/operators");
|
14 | class InvalidInputOptions extends core_1.schema.SchemaValidationException {
|
15 | constructor(options, errors) {
|
16 | super(errors, `Schematic input does not validate against the Schema: ${JSON.stringify(options)}\nErrors:\n`);
|
17 | }
|
18 | }
|
19 | exports.InvalidInputOptions = InvalidInputOptions;
|
20 |
|
21 | function validateOptionsWithSchema(registry) {
|
22 | return (schematic, options, context) => {
|
23 |
|
24 | options = (0, core_1.deepCopy)(options);
|
25 | const withPrompts = context ? context.interactive : true;
|
26 | if (schematic.schema && schematic.schemaJson) {
|
27 |
|
28 | return registry.compile(schematic.schemaJson).pipe((0, operators_1.mergeMap)((validator) => validator(options, { withPrompts })), (0, operators_1.first)(), (0, operators_1.map)((result) => {
|
29 | if (!result.success) {
|
30 | throw new InvalidInputOptions(options, result.errors || []);
|
31 | }
|
32 | return options;
|
33 | }));
|
34 | }
|
35 | return (0, rxjs_1.of)(options);
|
36 | };
|
37 | }
|
38 | exports.validateOptionsWithSchema = validateOptionsWithSchema;
|