-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtool.js
More file actions
52 lines (46 loc) · 1.46 KB
/
tool.js
File metadata and controls
52 lines (46 loc) · 1.46 KB
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
const fs = require('fs')
const path = require('path')
const baseDir = path.resolve('./public')
const domain = 'https://www.zzmark.top'
// 只打印需要CDN 预热的
const isCDNWarmup = false
// 调用文件遍历方法
fileDisplay(baseDir)
/**
* 文件遍历方法
* @param filePath 需要遍历的文件路径
*/
function fileDisplay(filePath) {
// 根据文件路径读取文件,返回文件列表
fs.readdir(filePath, function (err, files) {
if (err) {
console.warn(err)
} else {
// 遍历读取到的文件列表
files.forEach(function (filename) {
// 获取当前文件的绝对路径
const filedir = path.join(filePath, filename)
fs.stat(filedir, function (eror, stats) {
if (eror) {
console.warn('获取文件stats失败')
} else {
if (stats.isFile()) {
// 打印文件名
if(isCDNWarmup && stats.size < 100000) {
return
}
let fullFilePath = filedir + ''
if(filename === 'index.html') {
fullFilePath = fullFilePath.replace('index.html', '')
}
console.log(domain + fullFilePath.substr(baseDir.length).split("\\").join("/"))
}
if (stats.isDirectory()) {
fileDisplay(filedir)//递归,如果是文件夹,就继续遍历该文件夹下面的文件
}
}
})
})
}
})
}