add 配置读取写入
This commit is contained in:
30
util/config/config.js
Normal file
30
util/config/config.js
Normal file
@@ -0,0 +1,30 @@
|
||||
"use strict";
|
||||
|
||||
const fs = require("fs");
|
||||
const {cwd} = require("process");
|
||||
const path = require('path');
|
||||
let configPath = path.join(cwd(), "/config.json");
|
||||
|
||||
/**
|
||||
* 获取配置文件
|
||||
* @returns {JSON}
|
||||
*/
|
||||
function getConfig() {
|
||||
let file = fs.readFileSync(configPath);
|
||||
return JSON.parse(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存配置文件
|
||||
* @param string {JSON}
|
||||
* @return {boolean}
|
||||
*/
|
||||
function setConfig(string) {
|
||||
fs.writeFileSync("config.json", JSON.stringify(string, null, 2));
|
||||
return getConfig() === string;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getConfig,
|
||||
setConfig
|
||||
}
|
||||
Reference in New Issue
Block a user