-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathgen_list.js
51 lines (47 loc) · 1.66 KB
/
gen_list.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
const fs = require('fs');
const path = require('path');
async function dirSize(dirPath) {
let minSize = Number.MAX_SAFE_INTEGER;
const files = await fs.promises.readdir(dirPath, { withFileTypes: true });
const exts = ['.md', '.jpg', '.png', '.jpeg', '.log', '.gitignore', '.props', '.json'];
const filteredFiles = files.filter(file => {
const ext = path.extname(file.name);
return !file.name.startsWith('.') && !exts.includes(ext);
});
const sizes = filteredFiles.map(async file => {
const filePath = path.join(dirPath, file.name);
const stats = await fs.promises.stat(filePath);
if (stats.isDirectory()) {
return await dirSize(filePath);
}
return stats.size;
});
return await Promise.all(sizes).then(sizes => {
const minSizeInDir = Math.min(...sizes);
return minSizeInDir === Number.MAX_SAFE_INTEGER ? 0 : minSizeInDir;
});
}
async function main() {
const currentPath = process.cwd();
const dirs = await fs.promises.readdir(currentPath, { withFileTypes: true });
const userSizeMap = new Map();
for (const dir of dirs) {
if (dir.name.startsWith('.') || !dir.isDirectory()) {
continue;
}
const key = dir.name;
const dirPath = path.join(currentPath, key);
const minSize = await dirSize(dirPath);
if (minSize === 0) {
continue;
}
userSizeMap.set(key, minSize);
}
const userSizeVec = Array.from(userSizeMap.entries()).sort((a, b) => a[1] - b[1]);
console.log('| index | user | size |');
console.log('|:-----:|:----------:|:---------:|');
userSizeVec.forEach(([user, size], index) => {
console.log(`\| ${index + 1} | ${user} | ${size} Bytes |`);
});
}
main();