-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
93 lines (84 loc) · 2.26 KB
/
index.ts
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env node
import fg from "fast-glob";
import fs from "fs";
const main = async () => {
let gitIgnore: string[] = [];
try {
gitIgnore = fs
.readFileSync(".gitignore", "utf8")
.toString()
.split("\n")
.filter((line) => line.length > 0 && line[0] !== "#")
.map((line) => (line.endsWith("/") ? line.slice(0, -1) : line));
} catch (e) {
console.log("No .gitignore file found");
}
const entries = (
await fg("**/*", {
ignore: gitIgnore,
})
).filter(
(file: string) =>
file.endsWith(".ts") ||
file.endsWith(".tsx") ||
file.endsWith(".js") ||
file.endsWith(".jsx") ||
file.endsWith(".css") ||
file.endsWith(".html")
);
const zIndexes = [];
const valueWidth = 8;
for (const entry of entries) {
const content = fs.readFileSync(entry, "utf8").toString();
let index = 0;
while (index != -1) {
if (
entry.endsWith(".ts") ||
entry.endsWith(".tsx") ||
entry.endsWith(".js") ||
entry.endsWith(".jsx")
) {
index = content.indexOf("zIndex:", index);
if (index != -1) {
const possibleValue = content.slice(
"zIndex:".length + index,
"zIndex:".length + index + valueWidth
);
const value = possibleValue.match(/\d+/);
if (value) {
zIndexes.push({
file: entry,
value: parseInt(value[0]),
});
}
index += valueWidth;
}
}
if (entry.endsWith(".css") || entry.endsWith(".html")) {
index = content.indexOf("z-index:", index);
if (index != -1) {
const possibleValue = content.slice(
"z-index:".length + index,
"z-index:".length + index + valueWidth
);
const value = possibleValue.match(/\d+/);
if (value) {
zIndexes.push({
file: entry,
value: parseInt(value[0]),
});
}
index += valueWidth;
}
} else {
index = -1;
}
}
}
zIndexes.sort((a, b) => a.value - b.value);
console.log("z-index - file:");
zIndexes.forEach((zIndex) => {
console.log(`${zIndex.value} - ${zIndex.file}`);
});
};
main();