Skip to content

Commit 20bb298

Browse files
clydinmgechev
authored andcommitted
refactor(@schematics/angular): allow followup rules with workspace helper
This change allows the `updateWorkspace` helper rule to optionally return a rule that will be executed after the workspace is updated.
1 parent ccfd58b commit 20bb298

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

packages/schematics/angular/utility/workspace.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
import { virtualFs, workspaces } from '@angular-devkit/core';
9-
import { Rule, Tree } from '@angular-devkit/schematics';
9+
import { Rule, Tree, noop } from '@angular-devkit/schematics';
1010
import { ProjectType } from './workspace-models';
1111

1212
function createHost(tree: Tree): workspaces.WorkspaceHost {
@@ -33,14 +33,14 @@ function createHost(tree: Tree): workspaces.WorkspaceHost {
3333
}
3434

3535
export function updateWorkspace(
36-
updater: (workspace: workspaces.WorkspaceDefinition) => void | PromiseLike<void>,
36+
updater: (workspace: workspaces.WorkspaceDefinition) => void | Rule | PromiseLike<void | Rule>,
3737
): Rule;
3838
export function updateWorkspace(
3939
workspace: workspaces.WorkspaceDefinition,
4040
): Rule;
4141
export function updateWorkspace(
4242
updaterOrWorkspace: workspaces.WorkspaceDefinition
43-
| ((workspace: workspaces.WorkspaceDefinition) => void | PromiseLike<void>),
43+
| ((workspace: workspaces.WorkspaceDefinition) => void | Rule | PromiseLike<void | Rule>),
4444
): Rule {
4545
return async (tree: Tree) => {
4646
const host = createHost(tree);
@@ -49,14 +49,15 @@ export function updateWorkspace(
4949

5050
const { workspace } = await workspaces.readWorkspace('/', host);
5151

52-
const result = updaterOrWorkspace(workspace);
53-
if (result !== undefined) {
54-
await result;
55-
}
52+
const result = await updaterOrWorkspace(workspace);
5653

5754
await workspaces.writeWorkspace(workspace, host);
55+
56+
return result || noop;
5857
} else {
5958
await workspaces.writeWorkspace(updaterOrWorkspace, host);
59+
60+
return noop;
6061
}
6162
};
6263
}

0 commit comments

Comments
 (0)