UNPKG

datapack-manager

Version:
63 lines (57 loc) 1.72 kB
#!/usr/bin/env node 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } var _tslib = require('./_virtual/_tslib.js'); var fs = require('fs'); var fs__default = _interopDefault(fs); var pth = _interopDefault(require('path')); var os = _interopDefault(require('os')); var util = require('./util.js'); class Config { constructor() { this.reload(); } reload() { let json; try { json = fs__default.readFileSync(Config.path).toString(); } catch (e) { json = ""; } if (!json) { return this.init(); } try { const config = JSON.parse(json); Object.assign(this, config); } catch (e) { return this.init(); } } init() { this.global = pth.join(util.getMinecraftPath(), "datapacks"); } save() { return _tslib.__awaiter(this, void 0, void 0, function* () { const dir = pth.dirname(Config.path); try { yield fs__default.promises.access(dir); } catch (e) { yield fs__default.promises.mkdir(dir, { recursive: true }); } return fs__default.promises.writeFile(Config.path, JSON.stringify(this, null, 2)); }); } toJSON() { return { global: this.global }; } } Config.path = pth.join(os.homedir(), ".config", "datapack-manager", "config"); var config = new Config(); exports.default = config;