forked from BM-laoli/Android-IOS-ReactNative
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
48 lines (38 loc) · 1 KB
/
Copy pathbuild.js
File metadata and controls
48 lines (38 loc) · 1 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
const fs = require("fs");
const clean = function (file) {
fs.writeFileSync(file, JSON.stringify({}));
};
const hasBuildInfo = function (file, path) {
const cacheFile = require(file);
return Boolean(cacheFile[path]);
};
const writeBuildInfo = function (file, path, id) {
const cacheFile = require(file);
cacheFile[path] = id;
fs.writeFileSync(file, JSON.stringify(cacheFile));
};
const getCacheFile = function (file, path) {
const cacheFile = require(file);
return cacheFile[path] || 0;
};
const isPwdFile = (path) => {
const cwd = __dirname.split("/").splice(-1, 1).toString();
const pathArray = path.split("/");
const map = new Map();
const reverseMap = new Map();
pathArray.forEach((it, indx) => {
map.set(it, indx);
reverseMap.set(indx, it);
});
if (pathArray.length - 2 == map.get(cwd)) {
return reverseMap.get(pathArray.length - 1).replace(/\.js/, "");
}
return "";
};
module.exports = {
hasBuildInfo,
writeBuildInfo,
getCacheFile,
clean,
isPwdFile,
};