1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var fs = require("fs");
|
4 |
|
5 |
|
6 |
|
7 | var ConfigurationFile;
|
8 | (function (ConfigurationFile) {
|
9 | |
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | function read(confPath, logger) {
|
17 | return new Promise(function (resolve, reject) {
|
18 | fs.readFile(confPath, "utf8", function (err, data) {
|
19 | if (err) {
|
20 | if (err.code !== "ENOENT")
|
21 | return void reject(err);
|
22 | logger.info("No game.json found. Create a new one.");
|
23 | data = "{}";
|
24 | }
|
25 | try {
|
26 | resolve(JSON.parse(data));
|
27 | }
|
28 | catch (e) {
|
29 | reject(e);
|
30 | }
|
31 | });
|
32 | });
|
33 | }
|
34 | ConfigurationFile.read = read;
|
35 | |
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | function write(content, confPath, logger) {
|
42 | return new Promise(function (resolve, reject) {
|
43 | var text = JSON.stringify(content, null, "\t");
|
44 | fs.writeFile(confPath, text, { encoding: "utf8" }, function (err) {
|
45 | if (err) {
|
46 | reject(err);
|
47 | }
|
48 | else {
|
49 | resolve();
|
50 | }
|
51 | });
|
52 | });
|
53 | }
|
54 | ConfigurationFile.write = write;
|
55 | })(ConfigurationFile = exports.ConfigurationFile || (exports.ConfigurationFile = {}));
|