UNPKG

sui-direct

Version:

Decentralized version control system on SUI blockchain

31 lines (30 loc) 1.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const path_1 = require("path"); const fs_1 = require("fs"); class JSONIO { static read(path, absolutePath = false) { const data = (0, fs_1.readFileSync)(absolutePath ? path : (0, path_1.join)(__dirname, path), "utf-8"); const parsedData = JSON.parse(data); return parsedData; } static write(path, data, absolutePath = false) { const jsonData = JSON.stringify(data, null, 4); (0, fs_1.writeFileSync)(absolutePath ? path : (0, path_1.join)(__dirname, path), jsonData, "utf-8"); } static ensureConfigExists() { if (!(0, fs_1.existsSync)(this.configPath)) { (0, fs_1.writeFileSync)(this.configPath, JSON.stringify({}), "utf-8"); } } static getConfig() { this.ensureConfigExists(); return JSONIO.read(this.configPath, true); } static setConfig(data) { this.ensureConfigExists(); JSONIO.write(this.configPath, data, true); } } JSONIO.configPath = (0, path_1.join)(__dirname, "../../config.json"); exports.default = JSONIO;