ptSend/util/config/config.js

31 lines
571 B
JavaScript

"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
* @return {boolean}
*/
function setConfig(string) {
console.info(string)
fs.writeFileSync("config.json", JSON.parse(string));
return getConfig() === string;
}
module.exports = {
getConfig,
setConfig
}