添加 kit 子目录
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
* 系统配置
|
||||
*/
|
||||
const os = require('os');
|
||||
const process = require('process');
|
||||
const path = require("path");
|
||||
const fs = require('fs');
|
||||
|
||||
module.exports = class SystemConfig {
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
static isWindows(){
|
||||
return os.platform() === 'win32'
|
||||
}
|
||||
|
||||
static isLinux(){
|
||||
return os.platform() === 'linux'
|
||||
}
|
||||
|
||||
static getShellEncode(){
|
||||
if ( this.isWindows() ) {
|
||||
return "GBK"
|
||||
} else {
|
||||
return "UTF-8"
|
||||
}
|
||||
}
|
||||
|
||||
static getLocalKitPath(){
|
||||
let path = "./"
|
||||
if ( this.isWindows() ) {
|
||||
path = require('path').dirname(require.main.filename)
|
||||
} else {
|
||||
path = process.execPath;
|
||||
}
|
||||
this.affirmDir(path)
|
||||
$logger.debug(`LocalKitPath=${path}`)
|
||||
return path;
|
||||
}
|
||||
|
||||
static getLocalStorePath(){
|
||||
const path = require("path")
|
||||
let dir = path.resolve(this.getLocalKitPath(), ".kit")
|
||||
this.affirmDir(dir)
|
||||
return dir;
|
||||
}
|
||||
|
||||
static getUserPath() {
|
||||
let userDirectory = '~';
|
||||
if ( this.isWindows() ) {
|
||||
userDirectory = process.env.USERPROFILE;
|
||||
}
|
||||
return userDirectory;
|
||||
}
|
||||
|
||||
static getUserConfigPath() {
|
||||
const path = require("path")
|
||||
const dir = path.resolve( this.getUserPath() , ".kit");
|
||||
this.affirmDir(dir)
|
||||
return dir;
|
||||
}
|
||||
|
||||
static getUserConfigFilePath() {
|
||||
const path = require("path")
|
||||
return path.resolve( this.getUserPath() , ".kit", "config.json");
|
||||
}
|
||||
|
||||
static getLogPath() {
|
||||
const path = require("path")
|
||||
let logs = path.resolve( this.getUserPath() , ".kit", "logs");
|
||||
this.affirmDir(logs)
|
||||
return logs
|
||||
}
|
||||
|
||||
/**
|
||||
* 确保目录存在
|
||||
* @param path
|
||||
*/
|
||||
static affirmDir(path){
|
||||
// 检查文件夹是否存在
|
||||
const exists = fs.existsSync(path);
|
||||
|
||||
if (! exists) {
|
||||
// 文件夹不存在
|
||||
try {
|
||||
fs.mkdirSync(path, { recursive: true });
|
||||
} catch (err) {
|
||||
// 处理错误
|
||||
log.error(`affirmDir ${path} error ${ err }`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user