forked from yuameshi/PhiCommunity-Bak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cfDeploy.js
60 lines (58 loc) · 1.4 KB
/
cfDeploy.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
const fs = require('fs');
const path = require('path');
listFile(process.cwd());
function listFile(filePath) {
fs.readdir(filePath, function (err, files) {
if (err) {
console.warn(err);
} else {
files.forEach(function (filename) {
var filedir = path.join(filePath, filename);
fs.stat(filedir, function (eror, stats) {
if (eror) {
console.warn('获取文件stats失败');
} else {
var isFile = stats.isFile();
var isDir = stats.isDirectory();
if (isFile) {
if (filedir.match(/.git|.github|.vscode/) == null) {
if (
filedir
.replace('phigros-html5', 'ph5')
.match(/html|js|css/) != null &&
filedir.match('cfDeploy.js') == null
) {
const fileData = fs
.readFileSync(filedir)
.toString();
if (
fileData.match(
'https://charts.phi.han-han.xyz/'
)
) {
console.log(
'Processing file:',
filedir
);
fs.writeFileSync(
filedir,
fileData.toString().replaceAll(
'https://charts.phi.han-han.xyz/',
'https://cf.charts.phi.han-han.xyz/'
)
);
}
}
}
}
if (isDir) {
if (filedir.match(/.git|.github|.vscode/) == null) {
listFile(filedir);
}
}
}
});
});
}
});
}