var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));var _createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _fileutils=require("../systemManager/fileutils");
var _logger=require("../systemManager/logger");
var _constants=require("../constants");var

Config=function(){
function Config(){(0,_classCallCheck2.default)(this,Config);
this.config={};
}(0,_createClass2.default)(Config,[{key:"initializeConfig",value:

function initializeConfig(c){
this.config=c;
return c;
}},{key:"getConfig",value:

function getConfig(){
return this.config;
}},{key:"getConfigValueSeparate",value:


function getConfigValueSeparate(key){var global=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;
var paths=this.config.paths;

if(!global&&!(0,_fileutils.fsExistsSync)(paths.project.config))return'N/A';
var cfg=global?
require(paths.GLOBAL_RNV_CONFIG):
require(paths.project.config);

var value=cfg[_constants.configSchema[key].key];
if(value===undefined)return'N/A';

return value;
}},{key:"getMergedConfigValue",value:

function getMergedConfigValue(key){var _this$config$buildCon;
var value=(_this$config$buildCon=this.config.buildConfig)==null?void 0:_this$config$buildCon[_constants.configSchema[key].key];
if(value===undefined&&_constants.configSchema[key].default){value=_constants.configSchema[key].default;}
return value;
}},{key:"listConfigValue",value:

function listConfigValue(key){
var localVal=this.getConfigValueSeparate(key).toString();
var globalVal=this.getConfigValueSeparate(key,true).toString();

if(globalVal==='N/A'&&_constants.configSchema[key].default){globalVal=_constants.configSchema[key].default;}
if(localVal==='N/A')localVal=globalVal;

var table=[
{
Key:key,
'Global Value':globalVal}];



if(localVal!=='N/A'){
table[0]['Project Value']=localVal;
}

return table;
}},{key:"isConfigValueValid",value:

function isConfigValueValid(key,value){
var keySchema=_constants.configSchema[key];
if(!keySchema){
(0,_logger.logWarning)("Unknown config param "+key);
return false;
}

if(keySchema.values&&!keySchema.values.includes(value)){
(0,_logger.logWarning)("Unsupported value provided for "+
key+". Correct values are "+keySchema.values.join(
', '));


return false;
}

return true;
}},{key:"setConfigValue",value:

function setConfigValue(key,value){
var _this$config=


this.config,global=_this$config.program.global,paths=_this$config.paths;

if(this.isConfigValueValid(key,value)){
var isValid=value;
var configPath=global?
paths.GLOBAL_RNV_CONFIG:
paths.project.config;
var config=require(configPath);

if(['true','false'].includes(isValid))isValid=isValid==='true';

config[_constants.configSchema[key].key]=isValid;
(0,_fileutils.writeFileSync)(configPath,config);
return true;
}
return false;
}},{key:"isAnalyticsEnabled",get:

function get(){
return this.getMergedConfigValue('analytics');
}}]);return Config;}();


var Conf=new Config();var _default=

Conf;exports.default=_default;
//# sourceMappingURL=config.js.map