Skip to content

Commit 516f52e

Browse files
clydinvikerman
authored andcommitted
feat(@angular-devkit/core): initial prompt provider json schema support
1 parent 4207a15 commit 516f52e

File tree

6 files changed

+647
-61
lines changed

6 files changed

+647
-61
lines changed

packages/angular_devkit/core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"dependencies": {
1111
"ajv": "~6.4.0",
1212
"chokidar": "^2.0.3",
13+
"fast-json-stable-stringify": "^2.0.0",
1314
"source-map": "^0.5.6",
1415
"rxjs": "^6.0.0"
1516
}

packages/angular_devkit/core/src/json/schema/interface.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { Observable } from 'rxjs';
8+
import { Observable, SubscribableOrPromise } from 'rxjs';
99
import { JsonArray, JsonObject, JsonValue } from '../interface';
1010

1111
export type JsonPointer = string & {
@@ -57,9 +57,13 @@ export interface SchemaValidatorResult {
5757
errors?: SchemaValidatorError[];
5858
}
5959

60+
export interface SchemaValidatorOptions {
61+
withPrompts: boolean;
62+
}
63+
6064
export interface SchemaValidator {
6165
// tslint:disable-next-line:no-any
62-
(data: any): Observable<SchemaValidatorResult>;
66+
(data: any, options?: Partial<SchemaValidatorOptions>): Observable<SchemaValidatorResult>;
6367
}
6468

6569
export interface SchemaFormatter {
@@ -90,8 +94,25 @@ export interface SchemaKeywordValidator {
9094
): boolean | Observable<boolean>;
9195
}
9296

97+
export interface PromptDefinition {
98+
id: string;
99+
type: string;
100+
message: string;
101+
default?: string | number | boolean | null;
102+
priority: number;
103+
validator?: (value: string) => boolean | string | Promise<boolean | string>;
104+
105+
items?: Array<string | { value: JsonValue, label: string }>;
106+
107+
raw?: string | JsonObject;
108+
}
109+
110+
export type PromptProvider = (definitions: Array<PromptDefinition>)
111+
=> SubscribableOrPromise<{ [id: string]: JsonValue }>;
112+
93113
export interface SchemaRegistry {
94114
compile(schema: Object): Observable<SchemaValidator>;
95115
addFormat(format: SchemaFormat): void;
96116
addSmartDefaultProvider<T>(source: string, provider: SmartDefaultProvider<T>): void;
117+
usePromptProvider(provider: PromptProvider): void;
97118
}

0 commit comments

Comments
 (0)