2018-04-16 13:03:54 +00:00
|
|
|
const os = require('os');
|
2018-04-18 06:47:00 +00:00
|
|
|
const path = require('path');
|
2018-10-22 18:02:47 +00:00
|
|
|
const fs = require('fs');
|
2018-04-16 13:03:54 +00:00
|
|
|
const { writeFile } = require('frappejs/server/utils');
|
|
|
|
|
|
|
|
const homedir = os.homedir();
|
|
|
|
const configFilePath = path.join(homedir, '.config', 'frappe-accounting', 'settings.json');
|
|
|
|
|
|
|
|
function getSettings() {
|
2018-07-14 13:15:21 +00:00
|
|
|
let settings;
|
|
|
|
try {
|
2018-10-22 18:02:47 +00:00
|
|
|
settings = JSON.parse(fs.readFileSync(configFilePath) || '{}');
|
2018-07-14 13:15:21 +00:00
|
|
|
} catch (e) {
|
|
|
|
settings = {};
|
|
|
|
}
|
2018-04-16 13:03:54 +00:00
|
|
|
|
2018-07-14 13:15:21 +00:00
|
|
|
return settings;
|
2018-04-16 13:03:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function saveSettings(settings) {
|
2018-07-14 13:15:21 +00:00
|
|
|
await writeFile(configFilePath, JSON.stringify(settings));
|
2018-04-16 13:03:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2018-07-14 13:15:21 +00:00
|
|
|
getSettings,
|
|
|
|
saveSettings
|
|
|
|
};
|