-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
82 lines (73 loc) · 2.42 KB
/
index.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const si = require('systeminformation');
const ProgressBar = require('progress');
// List of information functions to get
const tasks = [
{ name: 'CPU', fn: si.cpu },
{ name: 'GPU', fn: si.graphics },
{ name: 'Memory', fn: si.mem },
{ name: 'Storage', fn: si.diskLayout },
{ name: 'OS', fn: si.osInfo },
{ name: 'Motherboard', fn: si.baseboard }
];
// Loading bar
async function displaySystemInfo() {
const bar = new ProgressBar('Fetching system information :percent [:bar]', {
complete: '#',
incomplete: ' ',
width: 10,
total: tasks.length
});
bar.tick(0); // Start progress bar at 0%
const results = {};
const promises = tasks.map(({ name, fn }) => {
return fn()
.then(data => {
results[name] = data;
bar.tick(); // Update the progress bar
})
.catch(error => {
console.error(`Error fetching ${name} information:`, error);
results[name] = null;
bar.tick(); // Update the progress bar even if there's an error
});
});
await Promise.all(promises);
// Construct output
const output = [];
const { CPU: cpu, GPU: gpu, Memory: memory, Storage: storage, OS: os, Motherboard: motherboard } = results;
output.push('\n===============================');
output.push(' PC Specifications ');
output.push('===============================');
if (cpu) {
output.push(`CPU: ${cpu.manufacturer} ${cpu.brand} (${cpu.speed} GHz)`);
output.push(`Cores: ${cpu.cores}`);
}
output.push('-------------------------------');
if (motherboard) {
output.push(`Motherboard: ${motherboard.manufacturer} ${motherboard.model}`);
}
output.push('-------------------------------');
output.push('GPU:');
if (gpu && gpu.controllers) {
gpu.controllers.forEach((controller, index) => {
output.push(` ${index + 1}. ${controller.model} (${controller.vram} MB)`);
});
}
output.push('-------------------------------');
if (memory) {
output.push(`RAM: ${(memory.total / (1024 ** 3)).toFixed(2)} GB`);
}
output.push('-------------------------------');
output.push('Storage:');
if (storage) {
storage.forEach((disk, index) => {
output.push(` ${index + 1}. ${disk.name} ${disk.type} (${(disk.size / (1024 ** 3)).toFixed(2)} GB)`);
});
}
output.push('-------------------------------');
if (os) {
output.push(`OS: ${os.distro} ${os.release}`);
}
console.log(output.join('\n'));
}
displaySystemInfo();