UNPKG

zcatalyst-cli

Version:

Command Line Tool for CATALYST

79 lines (78 loc) 2.6 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CONFIG_KEYS = void 0; 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")); exports.CONFIG_KEYS = { node12_bin: 'node12.bin', node14_bin: 'node14.bin', node16_bin: 'node16.bin', node18_bin: 'node18.bin', node20_bin: 'node20.bin', node22_bin: 'node22.bin', node24_bin: 'node24.bin', python39_bin: 'python3_9.bin', python310_bin: 'python3_10.bin', python311_bin: 'python3_11.bin', python312_bin: 'python3_12.bin', python313_bin: 'python3_13.bin', java8_bin: 'java8.bin', java11_bin: 'java11.bin', java17_bin: 'java17.bin', java21_bin: 'java21.bin', java25_bin: 'java25.bin', javac_disableWarnings: 'javac.disable_warnings', serve_container: 'serve.container', functionsShell_prompt: 'functions_shell.prompt' }; class UserConfig { constructor() { this.configFilePath = path_1.default.join(constants_1.ENVPATH.userConfig.config, '.zcconfig'); this.config = {}; this.validKeys = Object.values(exports.CONFIG_KEYS); this.refresh(); } 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(); } has(key) { return key in this.config; } refresh() { this.config = fs_1.SYNC.readJSONFile(this.configFilePath, { checkpath: true }) || {}; } } exports.default = new UserConfig();