1 | import path from 'path'
|
2 |
|
3 | let getFileDepth = file => file.split(path.sep).length - 1
|
4 |
|
5 | let sortByFileDepth = (a, b) => {
|
6 | let depthA = getFileDepth(a)
|
7 | let depthB = getFileDepth(b)
|
8 | let depthDelta = depthA - depthB
|
9 |
|
10 | if (depthDelta !== 0) return depthDelta
|
11 |
|
12 | return a < b ? 1 : a > b ? -1 : 0
|
13 | }
|
14 |
|
15 | export default function sortSetsInMap(map) {
|
16 | for (let [key, value] of map) {
|
17 | if (value.size <= 1) continue
|
18 |
|
19 | map.set(key, new Set([...value].sort(sortByFileDepth)))
|
20 | }
|
21 | }
|