Initial commit
This commit is contained in:
59
Backend/dist/FileHandler.js
vendored
Normal file
59
Backend/dist/FileHandler.js
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
exports.__esModule = true;
|
||||
exports.FileHandler = void 0;
|
||||
var fs_1 = require("fs");
|
||||
var path = require("path");
|
||||
var Logger_1 = require("./Logger");
|
||||
var fs = require("fs-extra");
|
||||
var ensureDir = fs.ensureDir, pathExists = fs.pathExists, readJson = fs.readJson;
|
||||
var FileHandler = /** @class */ (function () {
|
||||
function FileHandler() {
|
||||
}
|
||||
FileHandler.prototype.load = function (callback) {
|
||||
var _this = this;
|
||||
Logger_1.Log('info', 'Preparing files');
|
||||
ensureDir(path.join(Undecked.dataPath), function (err) {
|
||||
if (err)
|
||||
throw err;
|
||||
_this.loadConfig(function () {
|
||||
callback();
|
||||
});
|
||||
});
|
||||
};
|
||||
FileHandler.prototype.loadConfig = function (callback) {
|
||||
var _this = this;
|
||||
this.configPath = path.join(Undecked.dataPath, 'config.json');
|
||||
pathExists(this.configPath, function (err, exists) {
|
||||
if (err)
|
||||
throw err;
|
||||
if (exists) {
|
||||
readJson(_this.configPath, function (err, json) {
|
||||
if (err)
|
||||
throw err;
|
||||
Config = json;
|
||||
callback();
|
||||
});
|
||||
}
|
||||
else {
|
||||
Config = defaultConfig;
|
||||
_this.saveConfig(callback);
|
||||
}
|
||||
});
|
||||
};
|
||||
FileHandler.prototype.saveConfig = function (callback) {
|
||||
fs_1.writeFile(this.configPath, JSON.stringify(Config, null, 4), function (err) {
|
||||
if (err)
|
||||
Logger_1.Log('error', 'Error whilst saving config', err.message);
|
||||
if (callback)
|
||||
callback();
|
||||
});
|
||||
};
|
||||
return FileHandler;
|
||||
}());
|
||||
exports.FileHandler = FileHandler;
|
||||
var defaultConfig = {
|
||||
ports: {
|
||||
http: 9999
|
||||
},
|
||||
name: null
|
||||
};
|
||||
//# sourceMappingURL=FileHandler.js.map
|
||||
Reference in New Issue
Block a user