mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-17 02:54:21 +08:00
fix(@angular-devkit/schematics): fully support async rules
This commit is contained in:
parent
790a9622c4
commit
13abfd01ec
@ -426,7 +426,7 @@ export interface RequiredWorkflowExecutionContext {
|
|||||||
schematic: string;
|
schematic: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export declare type Rule = (tree: Tree, context: SchematicContext) => Tree | Observable<Tree> | Rule | Promise<void> | void;
|
export declare type Rule = (tree: Tree, context: SchematicContext) => Tree | Observable<Tree> | Rule | Promise<void> | Promise<Rule> | void;
|
||||||
|
|
||||||
export declare type RuleFactory<T extends object> = (options: T) => Rule;
|
export declare type RuleFactory<T extends object> = (options: T) => Rule;
|
||||||
|
|
||||||
|
@ -231,4 +231,4 @@ export type AsyncFileOperator = (tree: FileEntry) => Observable<FileEntry | null
|
|||||||
*/
|
*/
|
||||||
export type Source = (context: SchematicContext) => Tree | Observable<Tree>;
|
export type Source = (context: SchematicContext) => Tree | Observable<Tree>;
|
||||||
export type Rule = (tree: Tree, context: SchematicContext) =>
|
export type Rule = (tree: Tree, context: SchematicContext) =>
|
||||||
Tree | Observable<Tree> | Rule | Promise<void> | void;
|
Tree | Observable<Tree> | Rule | Promise<void> | Promise<Rule> | void;
|
||||||
|
@ -97,7 +97,16 @@ export function callRule(
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
} else if (isPromise(result)) {
|
} else if (isPromise(result)) {
|
||||||
return from(result).pipe(map(() => inputTree));
|
return from(result).pipe(
|
||||||
|
mergeMap(inner => {
|
||||||
|
if (typeof inner === 'function') {
|
||||||
|
// This is considered a Rule, chain the rule and return its output.
|
||||||
|
return callRule(inner, observableOf(inputTree), context);
|
||||||
|
} else {
|
||||||
|
return observableOf(inputTree);
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
);
|
||||||
} else if (TreeSymbol in result) {
|
} else if (TreeSymbol in result) {
|
||||||
return observableOf(result);
|
return observableOf(result);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user