-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscanningDev.js
53 lines (44 loc) · 1.37 KB
/
scanningDev.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
const fs = require("fs");
const path = require("path");
const getPackage = require("./getPackage");
const formatSize = require("./formatSize");
const getDirectorySize = require("./getDirectorySize");
const { node_modules_inside } = require("./config");
const nodeModulesPath = node_modules_inside;
const modules = fs.readdirSync(nodeModulesPath);
async function getModule() {
let obj = {};
const res = await getPackage("dependencies")
.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(nodeModulesPath, moduleName);
if (moduleName === ".yarn-integrity") {
return;
}
try {
const moduleSize = getDirectorySize(modulePath);
obj[moduleName.toString()] = formatSize(moduleSize);
} catch (error) {
console.error(
`Error calculating size for module ${moduleName}: ${error.message}`
);
}
});
}
return obj;
})
.catch((err) => console.log(err));
return res;
}
async function scanModule() {
const response = await getModule();
return response;
}
module.exports = scanModule;