| 75 | } |
| 76 | |
| 77 | async function callRuleAsync(rule: Rule, tree: Tree, context: SchematicContext): Promise<Tree> { |
| 78 | let result = await rule(tree, context); |
| 79 | |
| 80 | while (typeof result === 'function') { |
| 81 | // This is considered a Rule, chain the rule and return its output. |
| 82 | result = await result(tree, context); |
| 83 | } |
| 84 | |
| 85 | if (typeof result === 'undefined') { |
| 86 | return tree; |
| 87 | } |
| 88 | |
| 89 | if (isObservable(result)) { |
| 90 | result = await lastValueFrom(result.pipe(defaultIfEmpty(tree))); |
| 91 | } |
| 92 | |
| 93 | if (result && TreeSymbol in result) { |
| 94 | return result; |
| 95 | } |
| 96 | |
| 97 | throw new InvalidRuleResultException(result); |
| 98 | } |