-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
specUtils.ts
48 lines (38 loc) · 1.08 KB
/
specUtils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import _ from 'lodash'
import mockfs from 'mock-fs'
import path from 'path'
export const logFs = () => {
console.dir(getFs(), { depth: null })
}
export const getFsPath = (pathStr: string) => {
return _.get(getFs(), _.compact(pathStr.split(path.sep)))
}
export const getFs = () => {
const cwd = process.cwd().split(path.sep).slice(1)
const recurse = (dir, d) => {
if (_.isString(dir)) {
return dir
}
return _.extend({}, ..._.map(dir, (val, key) => {
let nextDepth = null
if (d !== null) {
if (d === -1) {
nextDepth = d + 1
} else if (!(d > cwd.length) && key === cwd[d]) {
key = 'foo'
nextDepth = d + 1
if (d === cwd.length - 1) {
return { '[cwd]': recurse(val._items, nextDepth) }
}
return recurse(val._items, nextDepth)
} else {
nextDepth = null
}
}
return {
[key]: recurse(val._content ? val._content.toString() : val._items, nextDepth),
}
}))
}
return recurse({ root: mockfs.getMockRoot() }, -1).root
}