UNPKG

zcatalyst-cli

Version:

Command Line Tool for CATALYST

55 lines (54 loc) 1.85 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const fs_1 = require("./util_modules/fs"); const constants_1 = require("./util_modules/constants"); const path_1 = __importDefault(require("path")); const error_1 = __importDefault(require("./error")); class UserConfig { constructor() { this.validKeys = [ 'python3_9.bin', 'java8.bin', 'java11.bin', 'java17.bin', 'javac.disable_warnings' ]; this.configFilePath = path_1.default.join(constants_1.ENVPATH.userConfig.config, '.zcconfig'); this.config = fs_1.SYNC.readJSONFile(this.configFilePath, { checkpath: true }) || {}; } set(key, value) { if (!this.validKeys.includes(key)) { throw new error_1.default('Invalid key provided', { exit: 1 }); } fs_1.SYNC.ensureFile(this.configFilePath); this.config[key] = value; const content = JSON.stringify(this.config, null, 2) + '\n'; fs_1.SYNC.writeFile(this.configFilePath, content, 'utf8'); return this.config; } get(key) { return this.config[key]; } delete(key) { if (!this.config[key]) { return false; } delete this.config[key]; const content = JSON.stringify(this.config, null, 2) + '\n'; fs_1.SYNC.writeFile(this.configFilePath, content, 'utf8'); return true; } list() { let result = ''; this.validKeys.forEach((entry) => { result += `${entry}=${this.config[entry] || ''}\n`; }); return result.trim(); } } exports.default = new UserConfig();