zcatalyst-cli
Version:
Command Line Tool for CATALYST
48 lines (47 loc) • 2 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateActiveDC = exports.getActiveDCType = exports.getActiveDC = void 0;
const ansi_colors_1 = require("ansi-colors");
const path_1 = require("path");
const config_store_js_1 = __importDefault(require("./config-store.js"));
const index_js_1 = __importDefault(require("../error/index.js"));
const dc_type_js_1 = __importDefault(require("./constants/lib/dc-type.js"));
function getActiveDC(dcOption) {
const envname = 'CATALYST_ACTIVE_DC';
if (process.env[envname] !== undefined) {
return process.env[envname];
}
if (dcOption === undefined) {
const argv = process.argv.slice(2);
const dcIdx = argv.indexOf('--dc');
if (dcIdx !== -1) {
dcOption = argv[dcIdx + 1];
}
}
if (typeof dcOption === 'string') {
const availableDcs = Object.keys(dc_type_js_1.default);
if (!availableDcs.includes(dcOption)) {
throw new index_js_1.default('Provide DC in global option is not valid: ' + dcOption, {
exit: 1,
errorId: 'DC-1',
arg: [ansi_colors_1.bold.red(dcOption), (0, ansi_colors_1.bold)(availableDcs.map((dc) => '* ' + dc).join('\n'))],
docPath: (0, path_1.join)(__dirname, './docs/dc.toml')
});
}
return dc_type_js_1.default[dcOption].value;
}
return config_store_js_1.default.get('active_dc', dc_type_js_1.default.us.value);
}
exports.getActiveDC = getActiveDC;
function getActiveDCType() {
const activeDC = getActiveDC();
return Object.values(dc_type_js_1.default).find((type) => type.value === activeDC);
}
exports.getActiveDCType = getActiveDCType;
function updateActiveDC(dc) {
config_store_js_1.default.set('active_dc', dc);
}
exports.updateActiveDC = updateActiveDC;