UNPKG

sfdx-ftw

Version:
76 lines 2.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const command_1 = require("@salesforce/command"); const core_1 = require("@salesforce/core"); const core_2 = require("@salesforce/core"); const url_1 = require("url"); const fs = require("fs"); const ws = require("../util/Workspace"); class ChecksConfig extends core_1.ConfigFile { static getFileName() { return './.forcechecks/config.json'; } } var VALID_KEY; (function (VALID_KEY) { VALID_KEY[VALID_KEY["defaultremotecheck"] = 0] = "defaultremotecheck"; VALID_KEY[VALID_KEY["defaultlocalcheck"] = 1] = "defaultlocalcheck"; })(VALID_KEY = exports.VALID_KEY || (exports.VALID_KEY = {})); class BaseConfig extends command_1.SfdxCommand { validateKey(key) { if (!(key in VALID_KEY)) throw new core_2.SfdxError(`Key ${key} is not valid for this command.`); } async getCheckConfig(key) { // validate key this.validateKey(key); const myConfig = await this.getChecksConfigFile(); return myConfig.get(key); } async setCheckConfig(key, value) { // validate the key and value this.validateKey(key); try { await this.validateValue(key, value); } catch (err) { throw err; } const myConfig = await this.getChecksConfigFile(); myConfig.set(key, value); await myConfig.write(); return true; } async getChecksConfigFile() { return await ChecksConfig.create({ isGlobal: false }); } async validateValue(key, value) { // get key as enum const keyEnum = VALID_KEY[key]; switch (keyEnum) { // must be a valid url case VALID_KEY.defaultremotecheck: try { new url_1.URL(value); } catch (err) { throw new core_2.SfdxError(`${value} does not resolve to a valid URL`); } break; // must be a valid directory case VALID_KEY.defaultlocalcheck: const baseDir = await ws.getBaseDir(); const concatDir = `${baseDir}/${value}`; const dirExists = fs.existsSync(concatDir); if (!dirExists) { throw new core_2.SfdxError(`Directory does not exist on this machine: ${concatDir}`); } } } } exports.BaseConfig = BaseConfig; // always require a project BaseConfig.requiresProject = true; //# sourceMappingURL=BaseConfig.js.map