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 fs_extra_1 = require("fs-extra");
|
11 | const path = __importStar(require("path"));
|
12 | class Config {
|
13 | constructor(stateDir) {
|
14 | this.stateDir = stateDir;
|
15 | this.getAll = async () => {
|
16 | return fs_extra_1.readJson(path.join(this.stateDir, 'config.json')).catch(() => ({}));
|
17 | };
|
18 | this.get = async (key) => {
|
19 | const origConfigObj = await this.getAll();
|
20 | return origConfigObj[key];
|
21 | };
|
22 | this.set = async (key, value) => {
|
23 | const origConfigObj = await this.getAll();
|
24 | const mergedConfigObj = Object.assign(Object.assign({}, origConfigObj), { [key]: value });
|
25 | await fs_extra_1.outputJson(path.join(this.stateDir, 'config.json'), mergedConfigObj);
|
26 | return mergedConfigObj;
|
27 | };
|
28 | }
|
29 | }
|
30 | exports.Config = Config;
|