(operator: FileOperator)
| 125 | } |
| 126 | |
| 127 | export function forEach(operator: FileOperator): Rule { |
| 128 | return (tree: Tree) => { |
| 129 | tree.visit((path, entry) => { |
| 130 | if (!entry) { |
| 131 | return; |
| 132 | } |
| 133 | const newEntry = operator(entry); |
| 134 | if (newEntry === entry) { |
| 135 | return; |
| 136 | } |
| 137 | if (newEntry === null) { |
| 138 | tree.delete(path); |
| 139 | |
| 140 | return; |
| 141 | } |
| 142 | if (newEntry.path != path) { |
| 143 | tree.rename(path, newEntry.path); |
| 144 | } |
| 145 | if (!newEntry.content.equals(entry.content)) { |
| 146 | tree.overwrite(newEntry.path, newEntry.content); |
| 147 | } |
| 148 | }); |
| 149 | }; |
| 150 | } |
| 151 | |
| 152 | export function composeFileOperators(operators: FileOperator[]): FileOperator { |
| 153 | return (entry: FileEntry) => { |
no test coverage detected