zcatalyst-cli
Version:
Command Line Tool for CATALYST
65 lines (64 loc) • 2.13 kB
JavaScript
;
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 = {
python39_bin: 'python3_9.bin',
java8_bin: 'java8.bin',
java11_bin: 'java11.bin',
java17_bin: 'java17.bin',
javac_disableWarnings: 'javac.disable_warnings',
serve_container: 'serve.container'
};
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();