-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsensitiveScan.js
68 lines (66 loc) · 1.89 KB
/
sensitiveScan.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const fs = require('node:fs')
const path = require('path')
const buildDir = 'dist' // 默认的打包文件夹名称
const suffixes = [
'.7z',
'.tar',
'.gz',
'.zip',
'.rar',
'.txt',
'.bak',
'.sql',
'.pyc',
'.swp',
'.old',
'~',
'.DS_Store',
'.sh',
'.gitignore'
] // 需要删除的文件夹后缀,全量删除
const folders = ['.git', '.svn', '.idea', 'WEB-INF', '.hg', '.bzr'] // 需要删除的文件夹,全量删除
const scanFolder = (folderPath, cb) => {
const tempFileList = []
const tempFolderList = []
fs.readdir(folderPath, (err, list) => {
if (!err) {
let i = 0
;(function iter() {
const subPath = list[i++]
if (!subPath) return cb(tempFileList, tempFolderList)
const filePath = path.join(folderPath, subPath)
fs.stat(filePath, (err, stat) => {
if (!err) {
if (stat.isDirectory()) {
// 如果是文件夹,并且不属于需要删除的文件夹范畴内,继续扫描,否则直接删除
if (folders.includes(subPath)) {
tempFolderList.push(filePath)
iter()
} else {
scanFolder(filePath, (tempFile, tempFolder) => {
tempFileList.push(...tempFile)
tempFolder.push(...tempFolder)
iter()
})
}
} else {
if (suffixes.includes(path.extname(filePath))) {
tempFileList.push(filePath)
}
iter()
}
}
})
})()
} else {
console.log('扫描文件夹失败')
cb(tempFileList, tempFolderList)
}
})
}
scanFolder(buildDir, (tempFileList, tempFolderList) => {
console.log('-----------涉敏文件--------------')
console.log(tempFileList)
console.log('-----------涉敏文件夹------------')
console.log(tempFolderList)
})