-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscanningAll.js
59 lines (49 loc) · 1.42 KB
/
scanningAll.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
const fs = require('fs');
const path = require('path');
const Table = require('cli-table');
const getPackage = require('./getPackage');
const formatSize = require('./formatSize');
const getDirectorySize = require('./getDirectorySize');
const { projectDirectory } = require('./config');
const modules = fs.readdirSync(projectDirectory);
const table = new Table({
head: ['Module', 'Size'],
colWidths: [30, 20],
});
async function getModule() {
let obj = {};
const res = await getPackage.then((response, err) => {
if (err) {
console.error('scanning package is failed');
return;
}
if (response) {
modules
// .filter(elem => response.includes(elem)
.forEach(moduleName => {
const modulePath = path.join(projectDirectory, moduleName);
if (moduleName === '.yarn-integrity') {
return;
}
try {
const moduleSize = getDirectorySize(modulePath);
table.push([moduleName, formatSize(moduleSize)]);
obj[moduleName.toString()] = formatSize(moduleSize);
} catch (error) {
console.error(
`Error calculating size for module ${moduleName}: ${error.message}`,
);
}
});
}
return obj;
});
return res;
}
async function scanModule() {
const response = await getModule();
if(response){
return response;
}
}
module.exports = scanModule;