mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-16 18:43:42 +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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
|
@ -231,4 +231,4 @@ export type AsyncFileOperator = (tree: FileEntry) => Observable<FileEntry | null
|
||||
*/
|
||||
export type Source = (context: SchematicContext) => Tree | Observable<Tree>;
|
||||
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)) {
|
||||
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) {
|
||||
return observableOf(result);
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user