修正 platform 命令

This commit is contained in:
cheney 2026-01-27 15:59:24 +08:00
parent 714572994a
commit d5e12945e1
4 changed files with 16 additions and 48 deletions

12
kit/package-lock.json generated
View File

@ -10,14 +10,13 @@
"dependencies": { "dependencies": {
"auto-launch": "^5.0.6", "auto-launch": "^5.0.6",
"cross-port-killer": "^1.4.0", "cross-port-killer": "^1.4.0",
"diskusage-ng": "^1.0.4",
"extract-zip": "^2.0.1", "extract-zip": "^2.0.1",
"get-port": "^7.0.0", "get-port": "^7.0.0",
"json5": "^2.2.3", "json5": "^2.2.3",
"log4js": "^6.9.1", "log4js": "^6.9.1",
"physical-cpu-count": "^2.0.0", "physical-cpu-count": "^2.0.0",
"sm-crypto": "^0.3.13", "sm-crypto": "^0.3.13",
"systeminformation": "^5.25.11", "systeminformation": "^5.30.6",
"webdav": "^5.3.1" "webdav": "^5.3.1"
}, },
"bin": { "bin": {
@ -158,15 +157,6 @@
} }
} }
}, },
"node_modules/diskusage-ng": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/diskusage-ng/-/diskusage-ng-1.0.4.tgz",
"integrity": "sha512-30qT0Bn2dNGii6dAXllGgYRaIt+7gPhwCJks+byhutkCOCgsqfqvXmAV2zTDOvU1ylnGHUjZMMaKhM95FyQQrg==",
"license": "MIT",
"engines": {
"node": ">=8.8.0"
}
},
"node_modules/end-of-stream": { "node_modules/end-of-stream": {
"version": "1.4.4", "version": "1.4.4",
"resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz",

View File

@ -14,14 +14,13 @@
"dependencies": { "dependencies": {
"auto-launch": "^5.0.6", "auto-launch": "^5.0.6",
"cross-port-killer": "^1.4.0", "cross-port-killer": "^1.4.0",
"diskusage-ng": "^1.0.4",
"extract-zip": "^2.0.1", "extract-zip": "^2.0.1",
"get-port": "^7.0.0", "get-port": "^7.0.0",
"json5": "^2.2.3", "json5": "^2.2.3",
"log4js": "^6.9.1", "log4js": "^6.9.1",
"physical-cpu-count": "^2.0.0", "physical-cpu-count": "^2.0.0",
"sm-crypto": "^0.3.13", "sm-crypto": "^0.3.13",
"systeminformation": "^5.25.11", "systeminformation": "^5.30.6",
"webdav": "^5.3.1" "webdav": "^5.3.1"
} }
} }

View File

@ -138,15 +138,19 @@ parser.addCmdLine("platform", "平台信息", function (cli) {
} }
table.push({ '项' : 'Mem ' + k, '值' : info.memory[k]}) table.push({ '项' : 'Mem ' + k, '值' : info.memory[k]})
} }
for ( let k in info.disk ){
if ( k.endsWith("Size") ) {
continue;
}
table.push({ '项' : 'Disk' + k, '值' : info.disk[k]})
}
console.table(table); console.table(table);
const disks = info.disk;
disks.forEach(disk => {
console.log(`磁盘 ${disk.mount}:`);
console.log(` 总空间: ${(disk.size / 1024 / 1024 / 1024).toFixed(2)} GB`);
console.log(` 已用空间: ${(disk.used / 1024 / 1024 / 1024).toFixed(2)} GB`);
console.log(` 可用空间: ${(disk.available / 1024 / 1024 / 1024).toFixed(2)} GB`);
console.log(` 使用率: ${disk.use}%`);
});
console.log( JSON.stringify(info, null, 4)); console.log( JSON.stringify(info, null, 4));
}).catch(error => { }).catch(error => {
console.error('Error getting device information:', error); console.error('Error getting device information:', error);
}); });

View File

@ -1,6 +1,5 @@
const os = require('os'); const os = require('os');
const diskusage = require('diskusage-ng'); const si = require('systeminformation');
const { physicalCpuCount } = require('physical-cpu-count');
const { formatBytes } = require("./util/convutil") const { formatBytes } = require("./util/convutil")
const { exec } = require('child_process'); const { exec } = require('child_process');
const { promisify } = require('util'); const { promisify } = require('util');
@ -14,6 +13,7 @@ const readFilePromise = promisify(fs.readFile);
// 获取操作系统信息 // 获取操作系统信息
async function getOSInfo() { async function getOSInfo() {
return { return {
type: os.type(), type: os.type(),
platform: os.platform(), platform: os.platform(),
@ -26,6 +26,7 @@ async function getOSInfo() {
// 获取 CPU 信息 // 获取 CPU 信息
function getCPUInfo() { function getCPUInfo() {
const cpus = os.cpus(); const cpus = os.cpus();
const physicalCpuCount = require('physical-cpu-count')
return { return {
model: cpus[0].model, model: cpus[0].model,
speed: cpus[0].speed, speed: cpus[0].speed,
@ -47,38 +48,13 @@ function getMemoryInfo() {
}); });
} }
// 获取硬盘信息
async function getDiskInfo() {
try {
const path = os.platform() === 'win32' ? 'C:' : '/';
return new Promise(function (resolve, reject) {
diskusage(path, function (err, usage) {
if (err) {
console.error('Error getting disk information:', err);
reject(err);
}
resolve({
totalSize: usage.total,
freeSize: usage.available,
total : formatBytes(usage.total),
free : formatBytes(usage.available),
});
});
})
} catch (error) {
console.error('Error getting disk information:', error);
return null;
}
}
// 主函数,调用上述函数获取所有信息 // 主函数,调用上述函数获取所有信息
async function getAllDeviceInfo() { async function getAllDeviceInfo() {
const osInfo = await getOSInfo(); const osInfo = await getOSInfo();
const cpuInfo = getCPUInfo(); const cpuInfo = getCPUInfo();
const memoryInfo = getMemoryInfo(); const memoryInfo = getMemoryInfo();
const diskInfo = await getDiskInfo(); const diskInfo = await si.fsSize();
return { return {
os: osInfo, os: osInfo,
@ -131,6 +107,5 @@ module.exports = {
getOSInfo, getOSInfo,
getCPUInfo, getCPUInfo,
getMemoryInfo, getMemoryInfo,
getDiskInfo,
getAllDeviceInfo getAllDeviceInfo
}; };