fix(@angular-devkit/schematics): fully support async rules

This commit is contained in:
Charles Lyding 2019-04-10 13:26:21 -04:00 committed by Alex Eagle
parent 790a9622c4
commit 13abfd01ec
3 changed files with 12 additions and 3 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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 {