Files
kit.program/kit/src/util/osutil.js
T
2025-03-11 16:50:44 +08:00

51 lines
1.3 KiB
JavaScript

const os = require('os');
const fs = require("fs");
const Windows = "Windows";
const Linux = "Linux";
module.exports = {
Windows, Linux,
/**
* 根据 os 不同,载入不同的方法
*/
choise : function ( cbs ) {
if (os.type() === 'Windows_NT') {
// windows平台
return cbs && cbs[ Windows ]
}
else if (os.type() === 'Linux') {
// Linux平台
return cbs && cbs[ Linux ]
}
else {
throw { message : "不支持的 OS" }
}
},
cur : function () {
let isLinux = false;
// 操作系统不同,安装方式不同
let curOS = os.type()
if ( curOS === "Windows_NT" ) {
curOS = "Windows"
}
else if ( curOS === "Linux" ) {
isLinux = true;
const fs = require('fs');
if( fs.existsSync('/etc/alpine-release') ){
curOS = "Alpine"
}
}
let curPlatform = os.arch()
if ( curPlatform === "x64" ) {
curPlatform = "X86_64"
} else if ( curPlatform.startsWith("arm") ) {
curPlatform = "ARM64"
}
return { isLinux, curOS, curPlatform }
}
}