(from: string, to?: string)
| 13 | export function move(from: string, to: string): Rule; |
| 14 | export function move(to: string): Rule; |
| 15 | export function move(from: string, to?: string): Rule { |
| 16 | if (to === undefined) { |
| 17 | to = from; |
| 18 | from = '/'; |
| 19 | } |
| 20 | |
| 21 | const fromPath = normalize('/' + from); |
| 22 | const toPath = normalize('/' + to); |
| 23 | |
| 24 | if (fromPath === toPath) { |
| 25 | return noop; |
| 26 | } |
| 27 | |
| 28 | return (tree) => { |
| 29 | if (tree.exists(fromPath)) { |
| 30 | // fromPath is a file |
| 31 | tree.rename(fromPath, toPath); |
| 32 | } else { |
| 33 | // fromPath is a directory |
| 34 | tree.getDir(fromPath).visit((path) => { |
| 35 | tree.rename(path, join(toPath, path.slice(fromPath.length))); |
| 36 | }); |
| 37 | } |
| 38 | |
| 39 | return tree; |
| 40 | }; |
| 41 | } |
no test coverage detected