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
69
70
71
72
73
74
var fs = require("fs-extra");
var path = require("path");
var AppName = ""
module.exports = {
/**
* 递归目录 检查文件名
* 参考 https://docs.cocos.com/creator/manual/zh/advanced-topics/meta.html
*/
findDirUuid: function (dir) {
if(AppName == '') {
AppName = this.getRootDirName(dir);
if(AppName != "") {
Editor.log("AppName: " + AppName);
}
}
var stat = fs.statSync(dir);
if (!stat.isDirectory()) {
return;
}
var subpaths = fs.readdirSync(dir),
subpath;
for (var i = 0; i < subpaths.length; ++i) {
if (subpaths[i][0] === ".") {
continue;
}
subpath = path.join(dir, subpaths[i]);
stat = fs.statSync(subpath);
if (stat.isDirectory()) {
this.findDirUuid(subpath);
} else if (stat.isFile()) {
var metastr = subpath.substr(subpath.length - 5, 5);
if (metastr != ".meta") {
this.check(AppName, subpaths[i]);
}
}
}
},
getRootDirName: function (path) {
let pArr = path.split("/");
let assteIndex = -1;
pArr.find((item, index) => {
if(item == 'assets') {
assteIndex = index;
return true
} else {
return false
}
})
if(assteIndex > 0 && assteIndex<(pArr.length-1)) {
return pArr[assteIndex + 1];
} else {
return ""
}
},
check: (appName, filePath) => {
if(escape(filePath).indexOf("%u")>=0) {
Editor.log(`检测到[中文或中文符号]命名的文件: ${filePath}`);
}
if (!/^\S*$/.test(filePath)) {
Editor.log(`检测到[包含空格]命名的文件: ${filePath}`);
}
if (/[-]/.test(filePath)) {
Editor.log(`检测到存在[包含减号(-)]命名的文件: ${filePath}`);
}
if(filePath.indexOf(appName) == -1 && (filePath.endsWith(".js") || filePath.endsWith(".ts"))) {
Editor.log(`检测到[不包含包名(${appName})]的文件: ${filePath}`);
}
}
};