UNPKG

datapack-manager

Version:
56 lines (53 loc) 1.44 kB
#!/usr/bin/env node import { __awaiter } from './_virtual/_tslib.js'; import fs$1 from 'fs'; import pth$1 from 'path'; import os$1 from 'os'; import { getMinecraftPath } from './util.js'; class Config { constructor() { this.reload(); } reload() { let json; try { json = fs$1.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$1.join(getMinecraftPath(), "datapacks"); } save() { return __awaiter(this, void 0, void 0, function* () { const dir = pth$1.dirname(Config.path); try { yield fs$1.promises.access(dir); } catch (e) { yield fs$1.promises.mkdir(dir, { recursive: true }); } return fs$1.promises.writeFile(Config.path, JSON.stringify(this, null, 2)); }); } toJSON() { return { global: this.global }; } } Config.path = pth$1.join(os$1.homedir(), ".config", "datapack-manager", "config"); var config = new Config(); export default config;