-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateTable.js
53 lines (39 loc) · 1.36 KB
/
createTable.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 Table = require('cli-table');
const getPackage = require('./getPackage');
const formatSize = require('./formatSize');
const getDirectorySize = require('./getDirectorySize');
const pc = require('picocolors');
const { projectDirectory } = require('./config');
// Function to get the size of a directory (including subdirectories)
// Path to your project's node_modules directory
// Get a list of modules within node_modules
const modules = fs.readdirSync(projectDirectory);
// Create a table for displaying the sizes
const table = new Table({
head: ['Module', 'Size'],
colWidths: [30, 20],
});
// Calculate and display the size of each module
let totalSize = 0;
async function createTable(arg) {
const module = arg ? await getPackage(arg) : modules;
module.forEach(moduleName => {
const modulePath = path.join(projectDirectory, moduleName);
try {
const moduleSize = getDirectorySize(modulePath);
table.push([moduleName, formatSize(moduleSize)]);
totalSize += moduleSize;
} catch (error) {
console.error(
`Error calculating size for module ${moduleName}: ${error.message}`,
);
}
});
// }
console.log(pc.green(table.toString()));
console.log(pc.green(`Total size of all modules: ${formatSize(totalSize)}`));
// });
}
module.exports = createTable;