Skip to content

Commit b0119c6

Browse files
committed
refactor(@angular-devkit/schematics): simplify move rule
1 parent dd48c4c commit b0119c6

File tree

1 file changed

+6
-18
lines changed
  • packages/angular_devkit/schematics/src/rules

1 file changed

+6
-18
lines changed

packages/angular_devkit/schematics/src/rules/move.ts

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
import { normalize } from '@angular-devkit/core';
9-
import { FileOperator, Rule } from '../engine/interface';
10-
import { FileEntry } from '../tree/interface';
11-
import { forEach } from './base';
9+
import { Rule } from '../engine/interface';
1210

1311

14-
export function moveOp(from: string, to?: string): FileOperator {
12+
export function move(from: string, to?: string): Rule {
1513
if (to === undefined) {
1614
to = from;
1715
from = '/';
@@ -20,19 +18,9 @@ export function moveOp(from: string, to?: string): FileOperator {
2018
const fromPath = normalize('/' + from);
2119
const toPath = normalize('/' + to);
2220

23-
return (entry: FileEntry) => {
24-
if (entry.path.startsWith(fromPath)) {
25-
return {
26-
content: entry.content,
27-
path: normalize(toPath + '/' + entry.path.substr(fromPath.length)),
28-
};
21+
return tree => tree.visit(path => {
22+
if (path.startsWith(fromPath)) {
23+
tree.rename(path, toPath + '/' + path.substr(fromPath.length));
2924
}
30-
31-
return entry;
32-
};
33-
}
34-
35-
36-
export function move(from: string, to?: string): Rule {
37-
return forEach(moveOp(from, to));
25+
});
3826
}

0 commit comments

Comments
 (0)