aboutsummaryrefslogtreecommitdiff
path: root/src/runtimeData/index.js
blob: 82531400b8232ab53b717da354a2372d8a27ab33 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
let fse = require("fs-extra");

class RuntimeData {

    constructor (DirUserData) {
        this.lockFile = DirUserData + "/config/runtime.json";
        this.runtimeVars = {};

        this.readFile();
        this.saveFile();
    };

    saveFile() {
        fse.outputJsonSync(this.lockFile, this.runtimeVars);
    }

    readFile() {
        try {
            this.runtimeVars = fse.readJsonSync(this.lockFile);
        } catch (err) {
            this.runtimeVars = {};
        }
    }

    set (name, value) {
        this.runtimeVars[name] = value;
        this.saveFile();
    };

    get (name) {
        this.readFile();
        if (typeof (this.runtimeVars[name]) != undefined) {
            return this.runtimeVars[name];
        } else {
            return false;
        }
    }

    unset (name) {
        delete this.runtimeVars[name];
    }

}

module.exports = RuntimeData;