1 | "use strict";
|
2 | var __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 | };
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | const util_1 = require("util");
|
11 | const fs = __importStar(require("fs"));
|
12 | async 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 | }
|
26 | exports.updateConfig = updateConfig;
|
27 | function 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 | }
|
33 | exports.writeConfig = writeConfig;
|
34 | function 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 | }
|
43 | exports.getConfig = getConfig;
|
44 |
|
\ | No newline at end of file |