UNPKG

@zendesk/zcli-core

Version:

ZCLI core libraries and services

34 lines (33 loc) 1.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CONFIG_PATH = void 0; const os = require("os"); const fs = require("fs-extra"); const path = require("path"); const HOME_DIR = os.homedir(); exports.CONFIG_PATH = path.join(HOME_DIR, '.zcli'); class Config { async ensureConfigFile() { if (!await fs.pathExists(exports.CONFIG_PATH)) { await fs.outputJson(exports.CONFIG_PATH, {}); } } async getConfig(key) { await this.ensureConfigFile(); const config = await fs.readJson(exports.CONFIG_PATH) || {}; return config[key]; } async setConfig(key, value) { await this.ensureConfigFile(); const config = await fs.readJson(exports.CONFIG_PATH) || {}; config[key] = value; await fs.outputJson(exports.CONFIG_PATH, config); } async removeConfig(key) { await this.ensureConfigFile(); const config = await fs.readJson(exports.CONFIG_PATH) || {}; delete config[key]; await fs.outputJson(exports.CONFIG_PATH, config); } } exports.default = Config;