var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.createRnvConfig=exports.parseRenativeConfigs=exports.loadEngines=exports.loadProjectTemplates=exports.listAppConfigsFoldersSync=exports.generateLocalConfig=exports.generateRuntimeConfig=exports.generateBuildConfig=exports.writeRenativeConfigFile=exports.loadFile=exports.versionCheck=exports.fixRenativeConfigsSync=exports.checkIsRenativeProject=exports.configureRuntimeDefaults=void 0;var _toConsumableArray2=_interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));
var _path=_interopRequireDefault(require("path"));
var _deepmerge=_interopRequireDefault(require("deepmerge"));
var _constants=require("../constants");

















var _engineManager=require("../engineManager");
var _utils=require("../utils");
var _fileutils=require("../systemManager/fileutils");













var _common=require("../common");

var _workspace=require("../projectManager/workspace");
var _logger=require("../systemManager/logger");








var _projectParser=require("../projectManager/projectParser");



var _prompt=require("../../cli/prompt");
var _pluginManager=require("../pluginManager");

var IGNORE_FOLDERS=['.git'];


var configureRuntimeDefaults=function configureRuntimeDefaults(c){var _c$files$project,_c$files$project$conf,_c$files$project$conf2,_c$buildConfig,_c$buildConfig$defaul,_c$buildConfig$defaul2,_PLATFORMS$c$platform;var _c$files$workspace$co,_c$files$workspace$co2,_c$buildConfig$defaul3,hosted;return _regenerator.default.async(function configureRuntimeDefaults$(_context){while(1){switch(_context.prev=_context.next){case 0:
c.runtime.appId=((_c$files$project=c.files.project)==null?void 0:(_c$files$project$conf=_c$files$project.configLocal)==null?void 0:(_c$files$project$conf2=_c$files$project$conf._meta)==null?void 0:_c$files$project$conf2.currentAppConfigId)||null;

(0,_logger.logTask)('configureRuntimeDefaults',"appId:"+c.runtime.appId);





c.runtime.port=c.program.port||((_c$buildConfig=
c.buildConfig)==null?void 0:(_c$buildConfig$defaul=_c$buildConfig.defaults)==null?void 0:(_c$buildConfig$defaul2=_c$buildConfig$defaul.ports)==null?void 0:_c$buildConfig$defaul2[c.platform])||((_PLATFORMS$c$platform=
_constants.PLATFORMS[c.platform])==null?void 0:_PLATFORMS$c$platform.defaultPort);
if(c.program.target!==true){
c.runtime.target=c.program.target||((_c$files$workspace$co=
c.files.workspace.config)==null?void 0:(_c$files$workspace$co2=_c$files$workspace$co.defaultTargets)==null?void 0:_c$files$workspace$co2[c.platform]);
}else c.runtime.target=c.program.target;
c.runtime.scheme=c.program.scheme||'debug';
c.runtime.localhost=_utils.isSystemWin?'127.0.0.1':'0.0.0.0';
c.runtime.timestamp=c.runtime.timestamp||Date.now();


c.configPropsInjects=c.configPropsInjects||[];
c.systemPropsInjects=c.systemPropsInjects||[];
c.runtimePropsInjects=[];

_constants.INJECTABLE_RUNTIME_PROPS.forEach(function(key){
c.runtimePropsInjects.push({
pattern:"{{runtimeProps."+key+"}}",
override:c.runtime[key]});

});
if(c.buildConfig){
c.runtime.bundleAssets=(0,_common.getConfigProp)(c,c.platform,'bundleAssets',false);
hosted=c.program.hosted;
c.runtime.hosted=(hosted||!c.runtime.scheme.bundleAssets)&&_constants.WEB_HOSTED_PLATFORMS.includes(c.platform);


if((_c$buildConfig$defaul3=c.buildConfig.defaults)==null?void 0:_c$buildConfig$defaul3.supportedPlatforms){
c.runtime.supportedPlatforms=c.buildConfig.defaults.supportedPlatforms.map(function(platform){var _engine$paths,_c$paths$project$plat,_c$buildConfig$defaul4,_PLATFORMS$platform;
var engine=(0,_engineManager.getEngineByPlatform)(c,platform);
var dir=engine==null?void 0:(_engine$paths=engine.paths)==null?void 0:_engine$paths.platformTemplatesDir;
var isConnected=false;
var isValid=false;
var pDir=(_c$paths$project$plat=c.paths.project.platformTemplatesDirs)==null?void 0:_c$paths$project$plat[platform];
if(pDir){
isValid=true;
isConnected=pDir==null?void 0:pDir.includes==null?void 0:pDir.includes((0,_fileutils.getRealPath)(c,dir));
}
var port=((_c$buildConfig$defaul4=c.buildConfig.defaults)==null?void 0:_c$buildConfig$defaul4[platform])||((_PLATFORMS$platform=_constants.PLATFORMS[platform])==null?void 0:_PLATFORMS$platform.defaultPort);
return{
engine:engine,
platform:platform,
isConnected:isConnected,
port:port,
isValid:isValid};

});
}
}return _context.abrupt("return",
true);case 13:case"end":return _context.stop();}}},null,null,null,Promise);};exports.configureRuntimeDefaults=configureRuntimeDefaults;


var checkIsRenativeProject=function checkIsRenativeProject(c){return new Promise(function(resolve,reject){
if(!c.paths.project.configExists){
return reject("Looks like this directory is not ReNative project. Project config "+
(0,_logger.chalk)().white(
c.paths.project.config)+" is missing!. You can create new project with "+
(0,_logger.chalk)().white(
'rnv new'));


}

return resolve();
});};exports.checkIsRenativeProject=checkIsRenativeProject;

var fixRenativeConfigsSync=function fixRenativeConfigsSync(c){return _regenerator.default.async(function fixRenativeConfigsSync$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:
(0,_logger.logTask)('fixRenativeConfigsSync');





(0,_projectParser.checkAndCreateGitignore)(c);


(0,_logger.logDebug)('configureProject:check babel config');
if(!(0,_fileutils.fsExistsSync)(c.paths.project.babelConfig)){
(0,_logger.logInfo)("Looks like your babel config file "+
(0,_logger.chalk)().white(
c.paths.project.babelConfig)+" is missing! CREATING...");


(0,_fileutils.copyFileSync)(
_path.default.join(c.paths.rnv.projectTemplate.dir,_constants.RN_BABEL_CONFIG_NAME),
c.paths.project.babelConfig);

}return _context2.abrupt("return",

true);case 5:case"end":return _context2.stop();}}},null,null,null,Promise);};exports.fixRenativeConfigsSync=fixRenativeConfigsSync;


var _generateConfigPaths=function _generateConfigPaths(pathObj,dir){
pathObj.dir=dir;
pathObj.config=_path.default.join(dir,_constants.RENATIVE_CONFIG_NAME);
pathObj.configLocal=_path.default.join(dir,_constants.RENATIVE_CONFIG_LOCAL_NAME);
pathObj.configPrivate=_path.default.join(dir,_constants.RENATIVE_CONFIG_PRIVATE_NAME);
pathObj.appConfigsDir=_path.default.join(dir,'..');
};

var versionCheck=function versionCheck(c){var _c$files$project2,_c$files$project2$con,_c$files$rnv,_c$files$rnv$package,_c$files$project3,_c$files$project3$pac,_c$files$project3$pac2;var recCmd,actionNoUpdate,actionWithUpdate,actionUpgrade,_await$inquirerPrompt,chosenAction;return _regenerator.default.async(function versionCheck$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:
(0,_logger.logTask)('versionCheck');if(!(

c.runtime.isWrapper||c.runtime.versionCheckCompleted||((_c$files$project2=c.files.project)==null?void 0:(_c$files$project2$con=_c$files$project2.config)==null?void 0:_c$files$project2$con.skipAutoUpdate))){_context3.next=3;break;}return _context3.abrupt("return",
true);case 3:

c.runtime.rnvVersionRunner=(_c$files$rnv=c.files.rnv)==null?void 0:(_c$files$rnv$package=_c$files$rnv.package)==null?void 0:_c$files$rnv$package.version;
c.runtime.rnvVersionProject=(_c$files$project3=c.files.project)==null?void 0:(_c$files$project3$pac=_c$files$project3.package)==null?void 0:(_c$files$project3$pac2=_c$files$project3$pac.devDependencies)==null?void 0:_c$files$project3$pac2.rnv;
(0,_logger.logTask)("versionCheck:rnvRunner:"+
c.runtime.rnvVersionRunner+",rnvProject:"+
c.runtime.rnvVersionProject,

(0,_logger.chalk)().grey);if(!(

c.runtime.rnvVersionRunner&&c.runtime.rnvVersionProject)){_context3.next=19;break;}if(!(
c.runtime.rnvVersionRunner!==c.runtime.rnvVersionProject)){_context3.next=19;break;}
recCmd=(0,_logger.chalk)().white("$ npx "+(0,_logger.getCurrentCommand)(true));
actionNoUpdate='Continue and skip updating package.json';
actionWithUpdate='Continue and update package.json';
actionUpgrade="Upgrade project to "+
c.runtime.rnvVersionRunner;_context3.next=14;return _regenerator.default.awrap(


(0,_prompt.inquirerPrompt)({
message:'What to do next?',
type:'list',
name:'chosenAction',
choices:[actionNoUpdate,actionWithUpdate,actionUpgrade],
warningMessage:"You are running $rnv v"+(0,_logger.chalk)().red(
c.runtime.rnvVersionRunner)+" against project built with rnv v"+
(0,_logger.chalk)().red(
c.runtime.rnvVersionProject)+". This might result in unexpected behaviour!\nIt is recommended that you run your rnv command with npx prefix: "+


recCmd+" . or manually update your devDependencies.rnv version in your package.json."}));case 14:_await$inquirerPrompt=_context3.sent;chosenAction=_await$inquirerPrompt.chosenAction;



c.runtime.versionCheckCompleted=true;

c.runtime.skipPackageUpdate=chosenAction===actionNoUpdate;

if(chosenAction===actionUpgrade){
(0,_projectParser.upgradeProjectDependencies)(c,c.runtime.rnvVersionRunner);
}case 19:return _context3.abrupt("return",


true);case 20:case"end":return _context3.stop();}}},null,null,null,Promise);};exports.versionCheck=versionCheck;


var loadFile=function loadFile(fileObj,pathObj,key){
var pKey=key+"Exists";
if(!(0,_fileutils.fsExistsSync)(pathObj[key])){
pathObj[pKey]=false;
(0,_logger.logDebug)("WARNING: loadFile: Path "+pathObj[key]+" does not exists!");
(0,_logger.logDebug)("FILE_EXISTS: "+key+":false path:"+pathObj[key]);
return false;
}
pathObj[pKey]=true;
try{
var fileString=(0,_fileutils.fsReadFileSync)(pathObj[key]).toString();
fileObj[key]=JSON.parse(fileString);
pathObj[pKey]=true;
(0,_logger.logDebug)("FILE_EXISTS: "+key+":true size:"+_formatBytes(Buffer.byteLength(fileString,'utf8')));
return true;
}catch(e){
(0,_logger.logError)("loadFile: "+pathObj[key]+" :: "+e,true);
return false;
}
};exports.loadFile=loadFile;


























var _arrayMergeOverride=function _arrayMergeOverride(destinationArray,sourceArray){return sourceArray;};


var getEnginesPluginDelta=function getEnginesPluginDelta(c){
(0,_logger.logDebug)('getEnginesPluginDelta');

if(!c.buildConfig)return;


var enginePlugins={};
var missingEnginePlugins={};


















var selectedEngine=(0,_engineManager.getEngineByPlatform)(c,c.platform,true);
if(selectedEngine==null?void 0:selectedEngine.plugins){
var ePlugins=Object.keys(selectedEngine.plugins);

if(ePlugins==null?void 0:ePlugins.length){
ePlugins.forEach(function(pluginKey){var _c$files,_c$files$project4,_c$files$project4$con;
if(!((_c$files=c.files)==null?void 0:(_c$files$project4=_c$files.project)==null?void 0:(_c$files$project4$con=_c$files$project4.config)==null?void 0:_c$files$project4$con[pluginKey])){
missingEnginePlugins[pluginKey]=selectedEngine.plugins[pluginKey];
}
enginePlugins[pluginKey]=selectedEngine.plugins[pluginKey];
});
}
}
c.runtime.missingEnginePlugins=missingEnginePlugins;
return enginePlugins;
};

var writeRenativeConfigFile=function writeRenativeConfigFile(c,configPath,configData){
(0,_logger.logDebug)("writeRenativeConfigFile:"+configPath);
(0,_fileutils.writeFileSync)(configPath,configData);
generateBuildConfig(c);
};exports.writeRenativeConfigFile=writeRenativeConfigFile;

var _formatBytes=function _formatBytes(bytes){var decimals=arguments.length>1&&arguments[1]!==undefined?arguments[1]:2;
if(bytes===0)return'0 Bytes';

var k=1024;
var dm=decimals<0?0:decimals;
var sizes=['Bytes','KB','MB','GB','TB','PB','EB','ZB','YB'];

var i=Math.floor(Math.log(bytes)/Math.log(k));

return parseFloat((bytes/Math.pow(k,i)).toFixed(dm))+" "+sizes[i];
};

var generateBuildConfig=function generateBuildConfig(c){
(0,_logger.logDebug)('generateBuildConfig');

var mergeOrder=[
c.paths.defaultWorkspace.config,
c.paths.rnv.projectTemplates.config,
c.paths.rnv.pluginTemplates.config,

c.paths.workspace.config,
c.paths.workspace.configPrivate,
c.paths.workspace.configLocal,
c.paths.workspace.project.config,
c.paths.workspace.project.configPrivate,
c.paths.workspace.project.configLocal].concat((0,_toConsumableArray2.default)(
c.paths.workspace.appConfig.configs),(0,_toConsumableArray2.default)(
c.paths.workspace.appConfig.configsPrivate),(0,_toConsumableArray2.default)(
c.paths.workspace.appConfig.configsLocal),[
c.paths.project.config,
c.paths.project.configPrivate,
c.paths.project.configLocal],(0,_toConsumableArray2.default)(
c.paths.appConfig.configs),(0,_toConsumableArray2.default)(
c.paths.appConfig.configsPrivate),(0,_toConsumableArray2.default)(
c.paths.appConfig.configsLocal));

var cleanPaths=mergeOrder.filter(function(v){return v;});
var existsPaths=cleanPaths.filter(function(v){
var exists=(0,_fileutils.fsExistsSync)(v);
if(exists){
(0,_logger.logDebug)("Merged: "+v);
}else{

}
return exists;
});

var pluginTemplates={};
if(c.files.rnv.pluginTemplates.configs){
Object.keys(c.files.rnv.pluginTemplates.configs).forEach(function(v){
var plgs=c.files.rnv.pluginTemplates.configs[v];
pluginTemplates[v]=plgs.pluginTemplates;
});
}

var extraPlugins=getEnginesPluginDelta(c);

var mergeFiles=[
c.files.defaultWorkspace.config,
c.files.rnv.projectTemplates.config,
{plugins:extraPlugins},

c.files.rnv.engines.config,
c.files.workspace.config,
c.files.workspace.configPrivate,
c.files.workspace.configLocal,
c.files.workspace.project.config,
c.files.workspace.project.configPrivate,
c.files.workspace.project.configLocal].concat((0,_toConsumableArray2.default)(
c.files.workspace.appConfig.configs),(0,_toConsumableArray2.default)(
c.files.workspace.appConfig.configsPrivate),(0,_toConsumableArray2.default)(
c.files.workspace.appConfig.configsLocal),[
c.files.project.config,
c.files.project.configPrivate,
c.files.project.configLocal],(0,_toConsumableArray2.default)(
c.files.appConfig.configs),(0,_toConsumableArray2.default)(
c.files.appConfig.configsPrivate),(0,_toConsumableArray2.default)(
c.files.appConfig.configsLocal));






var meta=[
{
_meta:{
generated:new Date().getTime(),
mergedConfigs:existsPaths}}];



var existsFiles=mergeFiles.filter(function(v){return v;});

(0,_logger.logDebug)("generateBuildConfig:mergeOrder.length:"+

mergeOrder.length+",cleanPaths.length:"+
cleanPaths.length+",existsPaths.length:"+
existsPaths.length+",existsFiles.length:"+
existsFiles.length);


var out=_deepmerge.default.all([].concat(meta,(0,_toConsumableArray2.default)(existsFiles)),{
arrayMerge:_arrayMergeOverride});

out=(0,_deepmerge.default)({},out);
out.pluginTemplates=pluginTemplates;

c.buildConfig=(0,_fileutils.sanitizeDynamicRefs)(c,out);
c.buildConfig=(0,_fileutils.sanitizeDynamicProps)(c.buildConfig,c.buildConfig._refs,{},c.runtime);

(0,_logger.logDebug)('BUILD_CONFIG',Object.keys(c.buildConfig));

if(c.runtime.appId){
c.paths.project.builds.config=_path.default.join(
c.paths.project.builds.dir,
c.runtime.appId+"_"+c.platform+".json");


(0,_logger.logDebug)("generateBuildConfig: will sanitize file at: "+

c.paths.project.builds.config);



if(c.paths.project.builds.dir){
var result=(0,_fileutils.writeFileSync)(c.paths.project.builds.config,c.buildConfig);
if(result){
var size=_formatBytes(Buffer.byteLength(result||'','utf8'));
(0,_logger.logTask)((0,_logger.chalk)().grey('generateBuildConfig'),"size:"+size);
}else{
(0,_logger.logDebug)("generateBuildConfig NOT SAVED: "+c.paths.project.builds.config);
}
}else{
(0,_logger.logWarning)('Cannot save buildConfig as c.paths.project.builds.dir is not defined');
}
}












};exports.generateBuildConfig=generateBuildConfig;

var _loadConfigFiles=function _loadConfigFiles(c,fileObj,pathObj,parseAppConfigs){
var result=false;
var extendAppId;
if(loadFile(fileObj,pathObj,'config')){
extendAppId=fileObj.config.extend||extendAppId;
result=true;
}

if(loadFile(fileObj,pathObj,'configLocal')){
extendAppId=fileObj.configLocal.extend||extendAppId;
result=true;
}

if(loadFile(fileObj,pathObj,'configPrivate')){
extendAppId=fileObj.configPrivate.extend||extendAppId;
result=true;
}


if(parseAppConfigs){
pathObj.dirs=[];
pathObj.fontsDirs=[];
pathObj.pluginDirs=[];
pathObj.configs=[];
pathObj.configsLocal=[];
pathObj.configsPrivate=[];

fileObj.configs=[];
fileObj.configsLocal=[];
fileObj.configsPrivate=[];
var fileObj1={};

var path1=_path.default.join(pathObj.appConfigsDir,'base');
var pathObj1={
config:_path.default.join(path1,_constants.RENATIVE_CONFIG_NAME),
configLocal:_path.default.join(path1,_constants.RENATIVE_CONFIG_LOCAL_NAME),
configPrivate:_path.default.join(path1,_constants.RENATIVE_CONFIG_PRIVATE_NAME)};

pathObj.dirs.push(path1);
pathObj.fontsDirs.push(_path.default.join(path1,'fonts'));
pathObj.pluginDirs.push(_path.default.join(path1,'plugins'));
pathObj.configs.push(pathObj1.config);
pathObj.configsPrivate.push(pathObj1.configPrivate);
pathObj.configsLocal.push(pathObj1.configLocal);

loadFile(fileObj1,pathObj1,'config');
loadFile(fileObj1,pathObj1,'configPrivate');
loadFile(fileObj1,pathObj1,'configLocal');
if(fileObj1.config)fileObj.configs.push(fileObj1.config);
if(fileObj1.configPrivate)fileObj.configsPrivate.push(fileObj1.configPrivate);
if(fileObj1.configLocal)fileObj.configsLocal.push(fileObj1.configLocal);


if((0,_fileutils.fsExistsSync)(pathObj.appConfigsDir)){
var appConfigsDirNames=(0,_fileutils.fsReaddirSync)(pathObj.appConfigsDir);
if(parseAppConfigs&&extendAppId&&appConfigsDirNames.includes(extendAppId)){
var path2=_path.default.join(pathObj.appConfigsDir,extendAppId);
var pathObj2={
config:_path.default.join(path2,_constants.RENATIVE_CONFIG_NAME),
configLocal:_path.default.join(path2,_constants.RENATIVE_CONFIG_LOCAL_NAME),
configPrivate:_path.default.join(path2,_constants.RENATIVE_CONFIG_PRIVATE_NAME)};

var fileObj2={};

pathObj.dirs.push(path2);
pathObj.fontsDirs.push(_path.default.join(path2,'fonts'));
pathObj.pluginDirs.push(_path.default.join(path2,'plugins'));
pathObj.configs.push(pathObj2.config);
pathObj.configsLocal.push(pathObj2.configLocal);
pathObj.configsPrivate.push(pathObj2.configPrivate);

loadFile(fileObj2,pathObj2,'config');
loadFile(fileObj2,pathObj2,'configPrivate');
loadFile(fileObj2,pathObj2,'configLocal');

if(fileObj2.config)fileObj.configs.push(fileObj2.config);
if(fileObj2.configLocal)fileObj.configsLocal.push(fileObj2.configLocal);
if(fileObj2.configPrivate)fileObj.configsPrivate.push(fileObj2.configPrivate);
}
}



var path3=pathObj.dir;
pathObj.dirs.push(path3);
pathObj.fontsDirs.push(_path.default.join(path3,'fonts'));
pathObj.pluginDirs.push(_path.default.join(path3,'plugins'));
pathObj.configs.push(_path.default.join(path3,_constants.RENATIVE_CONFIG_NAME));
pathObj.configsLocal.push(_path.default.join(path3,_constants.RENATIVE_CONFIG_LOCAL_NAME));
pathObj.configsPrivate.push(_path.default.join(path3,_constants.RENATIVE_CONFIG_PRIVATE_NAME));

if(fileObj.config)fileObj.configs.push(fileObj.config);
if(fileObj.configPrivate)fileObj.configsPrivate.push(fileObj.configPrivate);
if(fileObj.configLocal)fileObj.configsLocal.push(fileObj.configLocal);
}


generateBuildConfig(c);
return result;
};

var generateRuntimeConfig=function generateRuntimeConfig(c){var _c$buildConfig$common,_c$buildConfig$platfo,_c$buildConfig$platfo2;return _regenerator.default.async(function generateRuntimeConfig$(_context4){while(1){switch(_context4.prev=_context4.next){case 0:
(0,_logger.logTask)('generateRuntimeConfig');




c.assetConfig=(0,_fileutils.mergeObjects)(c,c.assetConfig,c.buildConfig.runtime||{});
c.assetConfig=(0,_fileutils.mergeObjects)(
c,
c.assetConfig,
((_c$buildConfig$common=c.buildConfig.common)==null?void 0:_c$buildConfig$common.runtime)||{});

c.assetConfig=(0,_fileutils.mergeObjects)(
c,
c.assetConfig,
((_c$buildConfig$platfo=c.buildConfig.platforms)==null?void 0:(_c$buildConfig$platfo2=_c$buildConfig$platfo[c.platform])==null?void 0:_c$buildConfig$platfo2.runtime)||{});

c.assetConfig=(0,_fileutils.mergeObjects)(
c,
c.assetConfig,
(0,_common.getConfigProp)(c,c.platform,'runtime')||{});


if((0,_fileutils.fsExistsSync)(c.paths.project.assets.dir)){
(0,_fileutils.writeFileSync)(c.paths.project.assets.config,c.assetConfig);
}return _context4.abrupt("return",
true);case 7:case"end":return _context4.stop();}}},null,null,null,Promise);};exports.generateRuntimeConfig=generateRuntimeConfig;


var generateLocalConfig=function generateLocalConfig(c,resetAppId){
(0,_logger.logTask)('generateLocalConfig',"resetAppId:"+!!resetAppId);
var configLocal=c.files.project.configLocal||{};

configLocal._meta=configLocal._meta||{};
if(resetAppId){
delete configLocal._meta.currentAppConfigId;
}else{
configLocal._meta.currentAppConfigId=c.runtime.appId;
}
c.files.project.configLocal=configLocal;
(0,_fileutils.writeFileSync)(c.paths.project.configLocal,configLocal);
};exports.generateLocalConfig=generateLocalConfig;

var _generatePlatformTemplatePaths=function _generatePlatformTemplatePaths(c){var _c$files$config,_c$files$config2,_c$files$config2$path,_c$files$config3;
(0,_logger.logTask)('_generatePlatformTemplatePaths');
if(!c.buildConfig.paths){
(0,_logger.logWarning)("You're missing paths object in your "+(0,_logger.chalk)().white(c.paths.project.config));
c.buildConfig.paths={};
}
if((_c$files$config=c.files.config)==null?void 0:_c$files$config.platformTemplatesDirs){
(0,_logger.logWarning)("DEPRECATED: platformTemplatesDirs in "+
(0,_logger.chalk)().white(c.paths.project.config)+" has been moved to engine config");
}
if((_c$files$config2=c.files.config)==null?void 0:(_c$files$config2$path=_c$files$config2.paths)==null?void 0:_c$files$config2$path.platformTemplatesDir){
(0,_logger.logWarning)("DEPRECATED: paths.platformTemplatesDir in "+
(0,_logger.chalk)().white(c.paths.project.config)+" has been moved to engine config");
}
if((_c$files$config3=c.files.config)==null?void 0:_c$files$config3.platformTemplatesDir){
(0,_logger.logWarning)("DEPRECATED: platformTemplatesDir in "+
(0,_logger.chalk)().white(c.paths.project.config)+" has been moved to engine config");
}
var pt=c.buildConfig.paths.platformTemplatesDirs||c.buildConfig.platformTemplatesDirs||{};
var result={};

c.buildConfig.defaults.supportedPlatforms.forEach(function(platform){var _engine$paths2;
var engine=(0,_engineManager.getEngineByPlatform)(c,platform);
var originalPath=engine==null?void 0:(_engine$paths2=engine.paths)==null?void 0:_engine$paths2.platformTemplatesDir;
if(originalPath){
if(!pt[platform]){
result[platform]=(0,_fileutils.getRealPath)(
c,
originalPath,
'platformTemplatesDir',
originalPath);

}else{
result[platform]=(0,_fileutils.getRealPath)(
c,
pt[platform],
'platformTemplatesDir',
originalPath);

}
}else{
(0,_logger.logWarning)("Platform "+(0,_logger.chalk)().red(platform)+" not supported by any registered engine. SKIPPING...");
}
});

return result;
};


var listAppConfigsFoldersSync=function listAppConfigsFoldersSync(c,ignoreHiddenConfigs){var _c$paths;
(0,_logger.logTask)('listAppConfigsFoldersSync',"ignoreHiddenConfigs:"+!!ignoreHiddenConfigs);

if(!((_c$paths=c.paths)==null?void 0:_c$paths.project))return[];

var dirPath=c.paths.project.appConfigsDir;

if(!(0,_fileutils.fsExistsSync)(dirPath))return[];
var appConfigsDirs=[];
(0,_fileutils.fsReaddirSync)(dirPath).forEach(function(dir){
var appConfigDir=_path.default.join(dirPath,dir);
if(
!IGNORE_FOLDERS.includes(dir)&&
(0,_fileutils.fsLstatSync)(appConfigDir).isDirectory())
{
if(ignoreHiddenConfigs){
var appConfig=_path.default.join(appConfigDir,_constants.RENATIVE_CONFIG_NAME);
if((0,_fileutils.fsExistsSync)(appConfig)){
try{
var config=(0,_fileutils.readObjectSync)(appConfig);
if((config==null?void 0:config.hidden)!==true){
appConfigsDirs.push(dir);
}
}catch(e){
(0,_logger.logWarning)("_listAppConfigsFoldersSync: "+e);
}
}
}else{
appConfigsDirs.push(dir);
}
}
});
return appConfigsDirs;
};exports.listAppConfigsFoldersSync=listAppConfigsFoldersSync;

var loadProjectTemplates=function loadProjectTemplates(c){
c.files.rnv.projectTemplates.config=(0,_fileutils.readObjectSync)(
c.paths.rnv.projectTemplates.config);

};exports.loadProjectTemplates=loadProjectTemplates;







var loadEngines=function loadEngines(c){
(0,_logger.logTask)('loadEngines');
c.files.rnv.engines.config=(0,_fileutils.readObjectSync)(
c.paths.rnv.engines.config);

};exports.loadEngines=loadEngines;

var _loadWorkspacesSync=function _loadWorkspacesSync(c){

if((0,_fileutils.fsExistsSync)(c.paths.rnv.configWorkspaces)){var _c$files$rnv$configWo;
(0,_logger.logDebug)(c.paths.rnv.configWorkspaces+" file exists!");
c.files.rnv.configWorkspaces=(0,_fileutils.readObjectSync)(
c.paths.rnv.configWorkspaces);


if(!c.files.rnv.configWorkspaces)c.files.rnv.configWorkspaces={};

if(!((_c$files$rnv$configWo=c.files.rnv.configWorkspaces)==null?void 0:_c$files$rnv$configWo.workspaces)){
c.files.rnv.configWorkspaces.workspaces={};
}
if(Object.keys(c.files.rnv.configWorkspaces.workspaces).length===0){
(0,_logger.logWarning)("No workspace found in "+

c.paths.rnv.configWorkspaces+". Creating default rnv one for you");


c.files.rnv.configWorkspaces.workspaces={
rnv:{
path:c.paths.workspace.dir}};


(0,_fileutils.writeFileSync)(
c.paths.rnv.configWorkspaces,
c.files.rnv.configWorkspaces);

}
}else{
(0,_logger.logWarning)("Cannot find "+
c.paths.rnv.configWorkspaces+". creating one..");

c.files.rnv.configWorkspaces={
workspaces:{
rnv:{
path:c.paths.workspace.dir}}};



(0,_fileutils.writeFileSync)(
c.paths.rnv.configWorkspaces,
c.files.rnv.configWorkspaces);

}
};


var parseRenativeConfigs=function parseRenativeConfigs(c){var workspaceAppConfigsDir;return _regenerator.default.async(function parseRenativeConfigs$(_context5){while(1){switch(_context5.prev=_context5.next){case 0:
(0,_logger.logTask)('parseRenativeConfigs');

loadFile(c.files.project,c.paths.project,'package');


_loadConfigFiles(c,c.files.project,c.paths.project);

if(c.runtime.appId){
c.paths.project.builds.config=_path.default.join(
c.paths.project.builds.dir,
c.runtime.appId+"_"+c.platform+".json");

}else{
c.paths.project.builds.config=_path.default.join(
c.paths.project.builds.dir,"<TBC>_"+
c.platform+".json");

}



loadFile(c.files.project.builds,c.paths.project.builds,'config');_context5.t0=


_generateConfigPaths;_context5.t1=
c.paths.workspace;_context5.t2=
_fileutils.getRealPath;_context5.t3=c;_context5.next=11;return _regenerator.default.awrap((0,_workspace.getWorkspaceDirPath)(c));case 11:_context5.t4=_context5.sent;_context5.t5=(0,_context5.t2)(_context5.t3,_context5.t4);(0,_context5.t0)(_context5.t1,_context5.t5);

_loadConfigFiles(c,c.files.workspace,c.paths.workspace);


_generateConfigPaths(c.paths.defaultWorkspace,c.paths.GLOBAL_RNV_DIR);
_loadConfigFiles(c,c.files.defaultWorkspace,c.paths.defaultWorkspace);


loadProjectTemplates(c);_context5.next=20;return _regenerator.default.awrap(


(0,_pluginManager.loadPluginTemplates)(c));case 20:





loadEngines(c);if(

c.files.project.config){_context5.next=24;break;}
(0,_logger.logDebug)("BUILD_CONFIG: c.files.project.config does not exists. path: "+c.paths.project.config);return _context5.abrupt("return");case 24:




_generateConfigPaths(
c.paths.workspace.project,
_path.default.join(c.paths.workspace.dir,c.files.project.config.projectName));

_loadConfigFiles(c,c.files.workspace.project,c.paths.workspace.project);

c.paths.workspace.project.appConfigBase.dir=_path.default.join(
c.paths.workspace.project.dir,
'appConfigs',
'base');


c.paths.workspace.project.appConfigBase.dir_LEGACY=_path.default.join(
c.paths.workspace.project.dir,
'projectConfig');


c.runtime.isWrapper=c.buildConfig.isWrapper;
c.paths.project.platformTemplatesDirs=_generatePlatformTemplatePaths(c);if(!


c.runtime.appId){_context5.next=48;break;}
if(!c.files.appConfig.config){
_generateConfigPaths(
c.paths.appConfig,
_path.default.join(c.paths.project.appConfigsDir,c.runtime.appId));

_loadConfigFiles(
c,
c.files.appConfig,
c.paths.appConfig,
true);

}

workspaceAppConfigsDir=(0,_fileutils.getRealPath)(
c,
c.buildConfig.workspaceAppConfigsDir);

c.paths.workspace.project.appConfigsDir=workspaceAppConfigsDir||
_path.default.join(c.paths.workspace.project.dir,'appConfigs');

_generateConfigPaths(
c.paths.workspace.appConfig,
_path.default.join(c.paths.workspace.project.appConfigsDir,c.runtime.appId));


_loadConfigFiles(
c,
c.files.workspace.appConfig,
c.paths.workspace.appConfig,
true);_context5.t6=



_generateConfigPaths;_context5.t7=
c.paths.workspace;_context5.t8=
_fileutils.getRealPath;_context5.t9=c;_context5.next=42;return _regenerator.default.awrap((0,_workspace.getWorkspaceDirPath)(c));case 42:_context5.t10=_context5.sent;_context5.t11=(0,_context5.t8)(_context5.t9,_context5.t10);(0,_context5.t6)(_context5.t7,_context5.t11);

_loadConfigFiles(c,c.files.workspace,c.paths.workspace);

generateLocalConfig(c);
generateBuildConfig(c);case 48:case"end":return _context5.stop();}}},null,null,null,Promise);};exports.parseRenativeConfigs=parseRenativeConfigs;



var createRnvConfig=function createRnvConfig(program,process,cmd,subCmd){var _ref=arguments.length>4&&arguments[4]!==undefined?arguments[4]:{},projectRoot=_ref.projectRoot;
var c={
cli:{},
runtime:{},
paths:{
rnv:{
pluginTemplates:{
configs:{}},

platformTemplates:{},
projectTemplates:{},
platformTemplate:{},
plugins:{},
engines:{},
projectTemplate:{}},

workspace:{
project:{
appConfigBase:{},
builds:{},
assets:{},
platformTemplates:{},
appConfigsDirs:[],
appConfigsDirNames:[]},

appConfig:{
configs:[],
configsPrivate:[],
configsLocal:[]}},


defaultWorkspace:{
project:{
appConfigBase:{},
builds:{},
assets:{},
platformTemplates:{},
appConfigsDirs:[],
appConfigsDirNames:[]},

appConfig:{
configs:[],
configsPrivate:[],
configsLocal:[]}},


project:{
appConfigBase:{},
builds:{},
assets:{},
platformTemplates:{},
appConfigsDirs:[],
appConfigsDirNames:[]},

appConfig:{
configs:[],
configsPrivate:[],
configsLocal:[]},


GLOBAL_RNV_DIR:'',
buildHooks:{
dist:{}},

home:{},
template:{
appConfigBase:{},
builds:{},
assets:{},
platformTemplates:{}}},


files:{
rnv:{
pluginTemplates:{},
platformTemplates:{},
projectTemplates:{},
platformTemplate:{},
plugins:{},
engines:{},
projectTemplate:{}},

workspace:{
project:{
appConfigBase:{},
builds:{},
assets:{},
platformTemplates:{}},

appConfig:{
configs:[],
configsPrivate:[],
configsLocal:[]}},


defaultWorkspace:{
project:{
appConfigBase:{},
builds:{},
assets:{},
platformTemplates:{}},

appConfig:{
configs:[],
configsPrivate:[],
configsLocal:[]}},


project:{
appConfigBase:{},
builds:{},
assets:{},
platformTemplates:{}},

appConfig:{
configs:[],
configsPrivate:[],
configsLocal:[]}}};




c.program=program;
c.process=process;
c.command=cmd;
c.subCommand=subCmd;
c.platformDefaults=_constants.PLATFORMS;

c.paths.rnv.dir=_constants.RNV_HOME_DIR;

c.paths.rnv.engines.dir=_path.default.join(
c.paths.rnv.dir,
'engineTemplates');

c.paths.rnv.pluginTemplates.dir=_path.default.join(
c.paths.rnv.dir,
'pluginTemplates');


c.paths.rnv.engines.config=_path.default.join(
c.paths.rnv.engines.dir,
_constants.RENATIVE_CONFIG_ENGINES_NAME);

c.paths.rnv.pluginTemplates.config=_path.default.join(
c.paths.rnv.pluginTemplates.dir,
_constants.RENATIVE_CONFIG_PLUGINS_NAME);

c.paths.rnv.projectTemplates.dir=_path.default.join(
c.paths.rnv.dir,
'projectTemplates');

c.paths.rnv.projectTemplates.config=_path.default.join(
c.paths.rnv.projectTemplates.dir,
_constants.RENATIVE_CONFIG_TEMPLATES_NAME);

c.paths.rnv.package=_path.default.join(c.paths.rnv.dir,'package.json');

c.paths.rnv.projectTemplate.dir=_path.default.join(
c.paths.rnv.dir,
'projectTemplate');

c.files.rnv.package=JSON.parse(
(0,_fileutils.fsReadFileSync)(c.paths.rnv.package).toString());


c.platform=c.program.platform;
c.paths.home.dir=_constants.USER_HOME_DIR;
c.paths.GLOBAL_RNV_DIR=_path.default.join(c.paths.home.dir,'.rnv');
c.paths.GLOBAL_RNV_CONFIG=_path.default.join(
c.paths.GLOBAL_RNV_DIR,
_constants.RENATIVE_CONFIG_NAME);

c.paths.rnv.configWorkspaces=_path.default.join(
c.paths.GLOBAL_RNV_DIR,
_constants.RENATIVE_CONFIG_WORKSPACES_NAME);


if(!(0,_fileutils.fsExistsSync)(c.paths.GLOBAL_RNV_DIR)){
(0,_fileutils.mkdirSync)(c.paths.GLOBAL_RNV_DIR);
}

_generateConfigPaths(c.paths.project,projectRoot||_constants.CURRENT_DIR);

c.paths.buildHooks.dir=_path.default.join(c.paths.project.dir,'buildHooks/src');
c.paths.buildHooks.dist.dir=_path.default.join(
c.paths.project.dir,
'buildHooks/dist');

c.paths.buildHooks.index=_path.default.join(c.paths.buildHooks.dir,'index.js');
c.paths.buildHooks.dist.index=_path.default.join(
c.paths.buildHooks.dist.dir,
'index.js');

c.paths.project.nodeModulesDir=_path.default.join(
c.paths.project.dir,
'node_modules');

c.paths.project.srcDir=_path.default.join(c.paths.project.dir,'src');
c.paths.project.appConfigsDir=_path.default.join(
c.paths.project.dir,
'appConfigs');

c.paths.project.package=_path.default.join(c.paths.project.dir,'package.json');
c.paths.project.rnCliConfig=_path.default.join(
c.paths.project.dir,
_constants.RN_CLI_CONFIG_NAME);

c.paths.project.babelConfig=_path.default.join(
c.paths.project.dir,
_constants.RN_BABEL_CONFIG_NAME);

c.paths.project.npmLinkPolyfill=_path.default.join(
c.paths.project.dir,
'npm_link_polyfill.json');

c.paths.project.appConfigBase.dir=_path.default.join(
c.paths.project.dir,
'appConfigs',
'base');

c.paths.project.appConfigBase.pluginsDir=_path.default.join(
c.paths.project.appConfigBase.dir,
'plugins');

c.paths.project.appConfigBase.fontsDir=_path.default.join(
c.paths.project.appConfigBase.dir,
'fonts');

c.paths.project.appConfigBase.fontsDirs=[
c.paths.project.appConfigBase.fontsDir];

c.paths.project.assets.dir=_path.default.join(
c.paths.project.dir,
'platformAssets');

c.paths.project.assets.runtimeDir=_path.default.join(
c.paths.project.assets.dir,
'runtime');

c.paths.project.assets.config=_path.default.join(
c.paths.project.assets.dir,
_constants.RENATIVE_CONFIG_RUNTIME_NAME);

c.paths.project.builds.dir=_path.default.join(
c.paths.project.dir,
'platformBuilds');


_generateConfigPaths(c.paths.workspace,c.paths.GLOBAL_RNV_DIR);


try{
_loadWorkspacesSync(c);
}catch(e){
(0,_logger.logError)(e);
}

return c;
};exports.createRnvConfig=createRnvConfig;
//# sourceMappingURL=configParser.js.map