-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
32 lines (30 loc) · 910 Bytes
/
index.js
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
const { getHash, joinHash } = require("./hash")
const { consoleError, joinPath } = require("./utils")
const readdir = require("fs-readdir-recursive")
const path = require("path")
const getAllHash = ({
projectPath,
folderPath,
filter,
hashLength = 8
} = {}) => {
const result = {}
try {
readdir(folderPath).forEach(file => {
if (filter && filter(file) !== true) return
const filePath = path.resolve(folderPath, file)
const projectAbsPath = path.resolve(projectPath)
let fileKey = filePath.replace(projectAbsPath, "")
if (path.sep !== "/") {
const { sep } = path
fileKey = fileKey.split(sep).join("/")
}
const filePathWithHash = joinHash(fileKey, getHash(filePath, hashLength))
result[joinPath(fileKey)] = joinPath(filePathWithHash)
})
} catch (err) {
consoleError(err)
}
return result
}
module.exports = getAllHash