| Conditions | 11 |
| Paths | 4 |
| Total Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like assets.js ➔ ... ➔ res.diffSet.forEach often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | import fse from 'fs-extra' |
||
| 33 | res.diffSet.forEach(function (entry) { |
||
| 34 | var state = { |
||
| 35 | 'equal' : '==', |
||
| 36 | 'left' : '->', |
||
| 37 | 'right' : '<-', |
||
| 38 | 'distinct' : '<>' |
||
| 39 | }[entry.state] |
||
| 40 | |||
| 41 | var name1 = entry.name1 ? entry.name1 : '' |
||
| 42 | var name2 = entry.name2 ? entry.name2 : '' |
||
| 43 | |||
| 44 | let exclude = new RegExp(config.files.exclude) |
||
| 45 | if(!exclude.test(name1) && !exclude.test(name2) && entry.type1 !== 'directory' && entry.type2 !== 'directory') { |
||
| 46 | |||
| 47 | if(typeof entry.path1 !== 'undefined' && entry.path1 !== null) { |
||
| 48 | var original = entry.path1 |
||
| 49 | var basePath = original.replace(publicFolder, '') |
||
| 50 | var move = path.join(dest, basePath) |
||
| 51 | |||
| 52 | if(entry.type2 === 'missing' || entry.state === 'distinct') { |
||
| 53 | fse.removeSync(move) |
||
| 54 | fse.copySync(original, move) |
||
| 55 | } |
||
| 56 | } |
||
| 57 | } |
||
| 58 | }) |
||
| 59 | }) |
||
| 62 | } |