UNPKG

1.48 kBJavaScriptView Raw
1"use strict";
2var __importStar = (this && this.__importStar) || function (mod) {
3 if (mod && mod.__esModule) return mod;
4 var result = {};
5 if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
6 result["default"] = mod;
7 return result;
8};
9Object.defineProperty(exports, "__esModule", { value: true });
10const util_1 = require("util");
11const fs = __importStar(require("fs"));
12async function updateConfig(newConfig, key) {
13 var config = await getConfig();
14 var keys = key.split('.');
15 keys.reduce(function (config, key, i) {
16 if (keys.length == i + 1) {
17 config[key] = newConfig;
18 console.log(config);
19 }
20 else if (typeof (config[key]) == 'undefined')
21 config[key] = {};
22 return config[key];
23 }, config);
24 writeConfig(config);
25}
26exports.updateConfig = updateConfig;
27function writeConfig(config) {
28 return util_1.promisify(fs.writeFile)('./config.json', JSON.stringify(config, null, 4), 'utf8').catch(function (err) {
29 if (err)
30 console.error(err);
31 });
32}
33exports.writeConfig = writeConfig;
34function getConfig() {
35 return util_1.promisify(fs.readFile)('./config.json', 'utf8').then(function (content) {
36 return JSON.parse(content);
37 }, function (err) {
38 writeConfig({}).then(function (config) {
39 return {};
40 });
41 });
42}
43exports.getConfig = getConfig;
44//# sourceMappingURL=config.js.map
\No newline at end of file