presidium 0.25.2 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/internal/pathWalk.js +29 -21
- package/internal/pathWalk.test.js +20 -11
- package/package.json +2 -1
package/internal/pathWalk.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require('rubico/global')
|
|
2
2
|
const fs = require('fs/promises')
|
|
3
|
+
const { minimatch } = require('minimatch')
|
|
3
4
|
const pathResolve = require('./pathResolve')
|
|
4
5
|
const isArray = require('./isArray')
|
|
5
6
|
|
|
@@ -20,29 +21,36 @@ const isArray = require('./isArray')
|
|
|
20
21
|
* }) // -> Promise<paths Array<string>>
|
|
21
22
|
* ```
|
|
22
23
|
*/
|
|
23
|
-
const pathWalk = function (path, options) {
|
|
24
|
-
const ignore =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
curry.arity(2, fs.readdir, __, { withFileTypes: true }),
|
|
29
|
-
() => []),
|
|
24
|
+
const pathWalk = async function (path, options = {}) {
|
|
25
|
+
const { ignore = [] } = options
|
|
26
|
+
const absPath = pathResolve(path)
|
|
27
|
+
const dirents = await fs.readdir(absPath, { withFileTypes: true })
|
|
28
|
+
const result = []
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
for (const dirent of dirents) {
|
|
31
|
+
const dirName = dirent.name
|
|
32
|
+
const dirPath = pathResolve(path, dirName)
|
|
33
|
+
let shouldIgnore = false
|
|
34
|
+
for (const pattern of ignore) {
|
|
35
|
+
if (minimatch(dirPath, pattern) || minimatch(dirName, pattern)) {
|
|
36
|
+
shouldIgnore = true
|
|
37
|
+
break
|
|
39
38
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (shouldIgnore) {
|
|
42
|
+
continue
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (dirent.isDirectory()) {
|
|
46
|
+
const subPaths = await pathWalk(dirPath, options)
|
|
47
|
+
result.push(...subPaths)
|
|
48
|
+
} else {
|
|
49
|
+
result.push(dirPath)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return result
|
|
46
54
|
}
|
|
47
55
|
|
|
48
56
|
module.exports = pathWalk
|
|
@@ -3,14 +3,23 @@ const Test = require('thunk-test')
|
|
|
3
3
|
const pathWalk = require('./pathWalk')
|
|
4
4
|
const pathResolve = require('./pathResolve')
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
.
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
const test = Test('pathWalk', pathWalk)
|
|
7
|
+
|
|
8
|
+
.case(__dirname, function (paths) {
|
|
9
|
+
assert(paths.length > 0)
|
|
10
|
+
this.allInternalPaths = paths
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
.case(__dirname, { ignore: ['pathWalk.js'] }, function (paths) {
|
|
14
|
+
assert.equal(paths.length, this.allInternalPaths.length - 1)
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
.case(__dirname, { ignore: [pathResolve(__dirname, 'pathWalk.js')] }, function (paths) {
|
|
18
|
+
assert.equal(paths.length, this.allInternalPaths.length - 1)
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
if (process.argv[1] == __filename) {
|
|
22
|
+
test()
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
module.exports = test
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "presidium",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"description": "A library for creating web services",
|
|
5
5
|
"author": "Richard Tong",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"aws-sdk": "^2.1123.0",
|
|
34
34
|
"bcrypt": "^5.1.0",
|
|
35
35
|
"ioredis": "^4.19.0",
|
|
36
|
+
"minimatch": "^9.0.3",
|
|
36
37
|
"mongodb": "^3.6.3",
|
|
37
38
|
"node-fetch": "^2.6.1",
|
|
38
39
|
"rubico": "latest",
|