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

var _constants=require("../constants");














var _fileutils=require("../systemManager/fileutils");














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








var IGNORE_FOLDERS=['.git'];

var checkIsRenativeProject=function checkIsRenativeProject(c){return new Promise(function(resolve,reject){
if(!c.paths.project.configExists){
return reject("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 _generateConfigPaths=function _generateConfigPaths(pathObj,dir,configName){
pathObj.dir=dir;
pathObj.config=_path.default.join(dir,configName||_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 _arrayMergeOverride=function _arrayMergeOverride(destinationArray,sourceArray){return sourceArray;};

var getEnginesPluginDelta=function getEnginesPluginDelta(c){var _c$runtime$enginesByP;
(0,_logger.logDebug)('getEnginesPluginDelta');

if(!c.buildConfig)return;


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

var engineConfig=(_c$runtime$enginesByP=c.runtime.enginesByPlatform[c.platform])==null?void 0:_c$runtime$enginesByP.config;
if(engineConfig!=null&&engineConfig.plugins){
var ePlugins=Object.keys(engineConfig.plugins);

if(ePlugins!=null&&ePlugins.length){
ePlugins.forEach(function(pluginKey){var _c$files,_c$files$project,_c$files$project$conf;
if(!((_c$files=c.files)!=null&&(_c$files$project=_c$files.project)!=null&&(_c$files$project$conf=_c$files$project.config)!=null&&_c$files$project$conf[pluginKey])){
missingEnginePlugins[pluginKey]=engineConfig.plugins[pluginKey];
}
enginePlugins[pluginKey]=engineConfig.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 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.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);
var propConfig={
files:c.files,
runtimeProps:c.runtime,
props:c.buildConfig._refs,
configProps:c.configPropsInjects};

c.buildConfig=(0,_fileutils.sanitizeDynamicProps)(c.buildConfig,propConfig);

(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=(0,_fileutils.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((0,_fileutils.loadFile)(fileObj,pathObj,'config',true)){
extendAppId=fileObj.config.extend||extendAppId;
result=true;
}

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

if((0,_fileutils.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);

(0,_fileutils.loadFile)(fileObj1,pathObj1,'config');
(0,_fileutils.loadFile)(fileObj1,pathObj1,'configPrivate');
(0,_fileutils.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);

(0,_fileutils.loadFile)(fileObj2,pathObj2,'config');
(0,_fileutils.loadFile)(fileObj2,pathObj2,'configPrivate');
(0,_fileutils.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));

(0,_fileutils.loadFile)(fileObj,pathObj,'config');
(0,_fileutils.loadFile)(fileObj,pathObj,'configPrivate');
(0,_fileutils.loadFile)(fileObj,pathObj,'configLocal');
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;var sanitizedConfig;return _regenerator.default.async(function generateRuntimeConfig$(_context){while(1){switch(_context.prev=_context.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)){
sanitizedConfig=(0,_fileutils.sanitizeDynamicProps)(c.assetConfig,{
files:c.files,
runtimeProps:c.runtime,
props:{},
configProps:c.configPropsInjects});

(0,_fileutils.writeFileSync)(c.paths.project.assets.config,sanitizedConfig);
c.files.project.assets.config=sanitizedConfig;
}return _context.abrupt("return",
true);case 7:case"end":return _context.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&&_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&&(_c$files$config2$path=_c$files$config2.paths)!=null&&_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&&_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=c.runtime.enginesByPlatform[platform];
if(engine){
var originalPath=engine.originalTemplatePlatformsDir;

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,appConfigsDirPath){var _c$paths;
(0,_logger.logTask)('listAppConfigsFoldersSync',"ignoreHiddenConfigs:"+!!ignoreHiddenConfigs);

if(!((_c$paths=c.paths)!=null&&_c$paths.project))return[];

var dirPath=appConfigsDirPath||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 _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&&_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$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:
(0,_logger.logTask)('parseRenativeConfigs');

(0,_fileutils.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");

}



(0,_fileutils.loadFile)(c.files.project.builds,c.paths.project.builds,'config');_context2.t0=


_generateConfigPaths;_context2.t1=
c.paths.workspace;_context2.t2=
_fileutils.getRealPath;_context2.t3=c;_context2.next=11;return _regenerator.default.awrap((0,_workspace.getWorkspaceDirPath)(c));case 11:_context2.t4=_context2.sent;_context2.t5=(0,_context2.t2)(_context2.t3,_context2.t4);(0,_context2.t0)(_context2.t1,_context2.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);


c.files.rnv.projectTemplates.config=(0,_fileutils.readObjectSync)(
c.paths.rnv.projectTemplates.config);if(





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




_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){_context2.next=46;break;}
if(!c.files.appConfig.config){




_generateConfigPaths(
c.paths.appConfig,
c.runtime.appConfigDir);

_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);


(0,_fileutils.loadFile)(c.files.project.assets,c.paths.project.assets,'config');_context2.t6=


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

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

generateLocalConfig(c);
generateBuildConfig(c);case 46:case"end":return _context2.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:{},
configPropsInjects:{},
runtime:{
enginesByPlatform:{},
enginesByIndex:[],
enginesById:{}},

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:[]}}};




global.RNV_CONFIG=c;

c.program=program;
c.process=process;
c.command=cmd;
c.subCommand=subCmd;


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.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,
'coreTemplateFiles');

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,
'coreTemplateFiles');

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.program.configName);

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.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=index.js.map