var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.getLocalRenativePlugin=exports.includesPluginPath=exports.sanitizePluginPath=exports.copyTemplatePluginsSync=exports.overrideTemplatePlugins=exports.installPackageDependenciesAndPlugins=exports.overrideFileContents=exports.loadPluginTemplates=exports.parsePlugins=exports.resolvePluginDependants=exports.configurePlugins=exports.getMergedPlugin=exports.getPluginList=void 0;var _toConsumableArray2=_interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));
var _deepmerge=_interopRequireDefault(require("deepmerge"));
var _path=_interopRequireDefault(require("path"));
var _prompt=require("../../cli/prompt");
var _common=require("../common");
var _configManager=require("../configManager");
var _constants=require("../constants");
var _fileutils=require("../systemManager/fileutils");




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




var _npmUtils=require("../systemManager/npmUtils");
var _resolve=require("../systemManager/resolve");function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable;});}keys.push.apply(keys,symbols);}return keys;}function _objectSpread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};if(i%2){ownKeys(Object(source),true).forEach(function(key){(0,_defineProperty2.default)(target,key,source[key]);});}else if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source));}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key));});}}return target;}


var getPluginList=function getPluginList(c){var isUpdate=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;
var output={
asString:'',
asArray:[],
plugins:[],
allPlugins:{}};


var i=1;

Object.keys(c.files.rnv.pluginTemplates.configs).forEach(function(pk){
var plugins=c.files.rnv.pluginTemplates.configs[pk].pluginTemplates;
Object.keys(plugins).forEach(function(k){
var p=plugins[k];

var platforms='';
c.runtime.availablePlatforms.forEach(function(v){
if(p[v])platforms+=v+", ";
});
if(platforms.length){
platforms=platforms.slice(0,platforms.length-2);
}
var installedPlugin=c.buildConfig&&
c.buildConfig.plugins&&
c.buildConfig.plugins[k];
var installedString=installedPlugin?
(0,_logger.chalk)().yellow('installed'):
(0,_logger.chalk)().green('not installed');
if(isUpdate&&installedPlugin){
output.plugins.push(k);
var versionString;
if(installedPlugin.version!==p.version){
versionString="("+(0,_logger.chalk)().yellow(
installedPlugin.version)+") => ("+
(0,_logger.chalk)().green(p.version)+")";
}else{
versionString="("+(0,_logger.chalk)().green(installedPlugin.version)+")";
}
output.asString+=" ["+i+"]> "+(0,_logger.chalk)().bold(
k)+" "+
versionString+"\n";
output.asArray.push({
name:k+" "+versionString,
value:k});

output.allPlugins[k]=p;
i++;
}else if(!isUpdate){
output.plugins.push(k);
output.asString+=" ["+i+"]> "+(0,_logger.chalk)().bold(k)+" ("+(0,_logger.chalk)().grey(
p.version)+") ["+
platforms+"] - "+installedString+"\n";
output.asArray.push({
name:k+" ("+(0,_logger.chalk)().grey(
p.version)+") ["+
platforms+"] - "+installedString,
value:k});

output.allPlugins[k]=p;

i++;
}
output.asArray.sort(function(a,b){
var aStr=a.name.toLowerCase();
var bStr=b.name.toLowerCase();
var com=0;
if(aStr>bStr){
com=1;
}else if(aStr<bStr){
com=-1;
}
return com;
});
});
});

return output;
};exports.getPluginList=getPluginList;


var _getPluginScope=function _getPluginScope(plugin){
if(typeof plugin==='string'||plugin instanceof String){
if(plugin.startsWith('source:')){
return{scope:plugin.split(':').pop()};
}
return{npmVersion:plugin};
}if(plugin!=null&&plugin.source){
return{scope:plugin==null?void 0:plugin.source};
}
return{scope:'rnv'};
};

var getMergedPlugin=function getMergedPlugin(c,key){var _c$buildConfig$plugin;
(0,_logger.logDebug)("getMergedPlugin:"+key);

var plugin=(_c$buildConfig$plugin=c.buildConfig.plugins)==null?void 0:_c$buildConfig$plugin[key];
if(!plugin)return null;

var scopes=[];
var mergedPlugin=_getMergedPlugin(c,plugin,key,null,scopes);
scopes.reverse();




mergedPlugin._scopes=scopes;
mergedPlugin._id=key;
return mergedPlugin;
};exports.getMergedPlugin=getMergedPlugin;

var _getMergedPlugin=function _getMergedPlugin(c,plugin,pluginKey,parentScope,scopes,skipSanitize){var _c$buildConfig$plugin2,_c$buildConfig$plugin3,_c$buildConfig$plugin4,_c$buildConfig;
if(!plugin){
return{};
}

var _getPluginScope2=_getPluginScope(plugin),scope=_getPluginScope2.scope,npmVersion=_getPluginScope2.npmVersion;
if(scope===parentScope)return plugin;

if(npmVersion){
return{
version:npmVersion};

}
if(scope!==''&&!!scope&&!((_c$buildConfig$plugin2=c.buildConfig.pluginTemplates)!=null&&_c$buildConfig$plugin2[scope])){
(0,_logger.logWarning)("Plugin "+
pluginKey+" is not recognized plugin in "+scope+" scope");

}else if(scope){
scopes.push(scope);
}

var parentPlugin=_getMergedPlugin(c,(_c$buildConfig$plugin3=
c.buildConfig.pluginTemplates)==null?void 0:(_c$buildConfig$plugin4=_c$buildConfig$plugin3[scope])==null?void 0:_c$buildConfig$plugin4[pluginKey],pluginKey,scope,scopes,true);
var currentPlugin=plugin;
if(typeof plugin==='string'||plugin instanceof String){
currentPlugin={};
}
_constants.INJECTABLE_CONFIG_PROPS.forEach(function(v){
c.configPropsInjects[v]=(0,_common.getConfigProp)(c,c.platform,v);
});
if(currentPlugin.pluginDependencies){
Object.keys(currentPlugin.pluginDependencies).forEach(function(plugDepKey){
if(currentPlugin.pluginDependencies[plugDepKey]==='source:self'){
currentPlugin.pluginDependencies[plugDepKey]="source:"+parentScope;
}
});
}
var mergedObj=(0,_fileutils.mergeObjects)(c,parentPlugin,currentPlugin,true,true);

var obj=skipSanitize?mergedObj:(0,_fileutils.sanitizeDynamicProps)(mergedObj,{
files:c.files,
runtimeProps:c.runtime,
props:(_c$buildConfig=c.buildConfig)==null?void 0:_c$buildConfig._refs,
configProps:c.configPropsInjects});



var mergedPlugin=skipSanitize?obj:(0,_fileutils.sanitizeDynamicProps)(obj,{
files:c.files,
runtimeProps:c.runtime,
props:obj.props,
configProps:c.configPropsInjects});


return mergedPlugin;
};

var configurePlugins=function configurePlugins(c){var _c$buildConfig2;var hasPackageChanged,newDeps,newDevDeps,_c$files$project$pack,dependencies,devDependencies;return _regenerator.default.async(function configurePlugins$(_context){while(1){switch(_context.prev=_context.next){case 0:
(0,_logger.logTask)('configurePlugins');if(!

c.program.skipDependencyCheck){_context.next=3;break;}return _context.abrupt("return",true);case 3:

if(!c.files.project.package.dependencies){
c.files.project.package.dependencies={};
}

hasPackageChanged=false;if((_c$buildConfig2=

c.buildConfig)!=null&&_c$buildConfig2.plugins){_context.next=7;break;}return _context.abrupt("return");case 7:



newDeps={};
newDevDeps={};_c$files$project$pack=
c.files.project.package,dependencies=_c$files$project$pack.dependencies,devDependencies=_c$files$project$pack.devDependencies;
Object.keys(c.buildConfig.plugins).forEach(function(k){
var plugin=getMergedPlugin(c,k);

if(!plugin){
(0,_logger.logWarning)("Plugin with name "+
(0,_logger.chalk)().white(
k)+" does not exists in ReNative source:rnv scope. you need to define it manually here: "+
(0,_logger.chalk)().white(
c.paths.project.builds.config));


}else if(dependencies&&dependencies[k]){
if(plugin['no-active']!==true&&plugin['no-npm']!==true&&
dependencies[k]!==plugin.version){
if(k==='renative'&&c.runtime.isWrapper){
(0,_logger.logWarning)(
"You're in ReNative wrapper mode. plugin renative will stay as local dep!");

}else{
(0,_logger.logWarning)("Version mismatch of dependency "+
(0,_logger.chalk)().white(
k)+" between:\n"+

(0,_logger.chalk)().white(c.paths.project.package)+": v("+(0,_logger.chalk)().red(dependencies[k])+") and\n"+
(0,_logger.chalk)().white(c.paths.project.builds.config)+": v("+(0,_logger.chalk)().green(
plugin.version)+").\npackage.json will be overriden");




hasPackageChanged=true;
newDeps[k]=plugin.version;
}
}
}else if(devDependencies&&devDependencies[k]){
if(
plugin['no-active']!==true&&
plugin['no-npm']!==true&&
devDependencies[k]!==plugin.version)
{
(0,_logger.logWarning)("Version mismatch of devDependency "+
(0,_logger.chalk)().white(
k)+" between package.json: v("+
(0,_logger.chalk)().red(
devDependencies[k])+") and plugins.json: v("+
(0,_logger.chalk)().red(
plugin.version)+"). package.json will be overriden");


hasPackageChanged=true;
newDevDeps[k]=plugin.version;
}
}else if(
plugin['no-active']!==true&&
plugin['no-npm']!==true)
{

if(plugin.version){
(0,_logger.logInfo)("Missing dependency "+
(0,_logger.chalk)().white(k)+" v("+(0,_logger.chalk)().red(
plugin.version)+") in package.json. INSTALLING...DONE");



hasPackageChanged=true;
newDeps[k]=plugin.version;
}
}

if(plugin&&plugin.npm){
Object.keys(plugin.npm).forEach(function(npmKey){
var npmDep=plugin.npm[npmKey];

var topLevelPlugin=getMergedPlugin(c,npmKey);
if(topLevelPlugin&&(topLevelPlugin==null?void 0:topLevelPlugin.version)!==npmDep){
(0,_logger.logInfo)("RNV Detected plugin dependency conflict. "+(0,_logger.chalk)().cyan('RESOLVING...')+"\n- "+
npmKey+"@"+(0,_logger.chalk)().green(topLevelPlugin==null?void 0:topLevelPlugin.version)+" "+(0,_logger.chalk)().cyan('<=')+"\n- "+
k+" .npm sub dependencies:\n   |- "+
npmKey+"@"+(0,_logger.chalk)().red(npmDep));
}else if(!dependencies[npmKey]){
(0,_logger.logInfo)("Plugin "+
(0,_logger.chalk)().white(
k)+" requires npm dependency "+
(0,_logger.chalk)().white(
npmKey)+". INSTALLING...DONE");


newDeps[npmKey]=npmDep;
hasPackageChanged=true;
}else if(dependencies[npmKey]!==npmDep){
(0,_logger.logWarning)("Plugin "+
(0,_logger.chalk)().white(
k)+" npm dependency "+
(0,_logger.chalk)().white(npmKey)+" mismatch ("+(0,_logger.chalk)().red(
dependencies[npmKey])+") => ("+
(0,_logger.chalk)().green(
npmDep)+") .updating npm dependency in your package.json");


newDeps[npmKey]=npmDep;
hasPackageChanged=true;
}
});
}
});




if(hasPackageChanged&&!c.runtime.skipPackageUpdate){
_updatePackage(c,{dependencies:newDeps,devDependencies:newDevDeps});
}return _context.abrupt("return",

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


var _updatePackage=function _updatePackage(c,override){
var newPackage=(0,_deepmerge.default)(c.files.project.package,override);
(0,_configManager.writeRenativeConfigFile)(c,c.paths.project.package,newPackage);
c.files.project.package=newPackage;
c._requiresNpmInstall=true;
};

var resolvePluginDependants=function resolvePluginDependants(c){var plugins,pluginKeys,i,key;return _regenerator.default.async(function resolvePluginDependants$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:
(0,_logger.logTask)('resolvePluginDependants');
plugins=c.buildConfig.plugins;if(!

plugins){_context2.next=12;break;}
pluginKeys=Object.keys(plugins);
i=0;case 5:if(!(i<pluginKeys.length)){_context2.next=12;break;}
key=pluginKeys[i];_context2.next=9;return _regenerator.default.awrap(
_resolvePluginDependencies(c,key,plugins[key],null));case 9:i++;_context2.next=5;break;case 12:return _context2.abrupt("return",



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


var _resolvePluginDependencies=function _resolvePluginDependencies(c,key,keyScope,parentKey){var pluginTemplates,plugin,_getPluginScope3,scope,_pluginTemplates$scop,depPlugin,_await$inquirerPrompt,confirm,deps,depsKeys,i,depKey,depScope;return _regenerator.default.async(function _resolvePluginDependencies$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:


pluginTemplates=c.buildConfig.pluginTemplates;
plugin=getMergedPlugin(c,key);_getPluginScope3=

_getPluginScope(keyScope),scope=_getPluginScope3.scope;if(

plugin){_context3.next=16;break;}
depPlugin=(_pluginTemplates$scop=pluginTemplates[scope])==null?void 0:_pluginTemplates$scop[key];if(!

depPlugin){_context3.next=13;break;}_context3.next=8;return _regenerator.default.awrap(

(0,_prompt.inquirerPrompt)({
type:'confirm',
message:"Install "+key+"?",
warningMessage:"Plugin "+(0,_logger.chalk)().white(key)+" source:"+
(0,_logger.chalk)().white(scope)+" required by "+(0,_logger.chalk)().red(parentKey)+" is not installed"}));case 8:_await$inquirerPrompt=_context3.sent;confirm=_await$inquirerPrompt.confirm;

if(confirm){
c.files.project.config.plugins[key]="source:"+scope;
(0,_configManager.writeRenativeConfigFile)(c,c.paths.project.config,c.files.project.config);
(0,_logger.logSuccess)("Plugin "+key+" sucessfully installed");
c._requiresNpmInstall=true;
}_context3.next=14;break;case 13:

(0,_logger.logWarning)("Plugin "+(0,_logger.chalk)().white(parentKey)+" requires "+
(0,_logger.chalk)().red(key)+" which is not available in your system");case 14:_context3.next=16;break;case 16:





deps=plugin==null?void 0:plugin.pluginDependencies;if(!
deps){_context3.next=28;break;}
depsKeys=Object.keys(deps);
i=0;case 20:if(!(i<depsKeys.length)){_context3.next=28;break;}
depKey=depsKeys[i];
depScope=deps[depKey];_context3.next=25;return _regenerator.default.awrap(
_resolvePluginDependencies(c,depKey,depScope,key));case 25:i++;_context3.next=20;break;case 28:return _context3.abrupt("return",


true);case 29:case"end":return _context3.stop();}}},null,null,null,Promise);};


var parsePlugins=function parsePlugins(c,platform,pluginCallback,ignorePlatformObjectCheck){
(0,_logger.logTask)('parsePlugins');
if(c.buildConfig){
var includedPlugins=(0,_common.getConfigProp)(
c,
platform,
'includedPlugins',
[]);

var excludedPlugins=(0,_common.getConfigProp)(
c,
platform,
'excludedPlugins',
[]);

if(includedPlugins){
var plugins=c.buildConfig.plugins;

if(plugins){
var totalIncludedPlugins=0;
Object.keys(plugins).forEach(function(key){
if(
(includedPlugins.includes('*')||
includedPlugins.includes(key))&&
!excludedPlugins.includes(key))
{
var plugin=getMergedPlugin(c,key);
if(plugin){
var pluginPlat=plugin[platform];
if(ignorePlatformObjectCheck){
totalIncludedPlugins++;
pluginCallback(plugin,pluginPlat,key);
}else if(pluginPlat){
if(
plugin['no-active']!==true&&
plugin.enabled!==false&&
pluginPlat.enabled!==false)
{
if(plugin.deprecated){
(0,_logger.logWarning)(plugin.deprecated);
}
if(pluginCallback){
totalIncludedPlugins++;
pluginCallback(plugin,pluginPlat,key);
}
}else{
(0,_logger.logWarning)("Plugin "+
key+" is marked disabled. skipping.");

}
}
}
}
});
if(totalIncludedPlugins===0){
(0,_logger.logWarning)("Found plugins in your app but non are included. are you sure you added "+
(0,_logger.chalk)().white('includedPlugins')+" in your renative.json config?");

}
}else{
(0,_logger.logError)("You have no plugins defined in "+
(0,_logger.chalk)().white(
c.paths.project.builds.config));


}
}else{
(0,_logger.logWarning)("You haven't included any "+
(0,_logger.chalk)().white(
'{ common: { includedPlugins: [] }}')+" in your "+
(0,_logger.chalk)().white(
c.paths.appConfig.config)+". Your app might not work correctly");


}
}
};exports.parsePlugins=parsePlugins;

var loadPluginTemplates=function loadPluginTemplates(c){var _c$files$project$conf,_c$files$project$conf2;var customPluginTemplates,missingDeps,dependencies,hasPackageChanged;return _regenerator.default.async(function loadPluginTemplates$(_context4){while(1){switch(_context4.prev=_context4.next){case 0:
(0,_logger.logTask)('loadPluginTemplates');
c.files.rnv.pluginTemplates.config=(0,_fileutils.readObjectSync)(
c.paths.rnv.pluginTemplates.config);


c.files.rnv.pluginTemplates.configs={
rnv:c.files.rnv.pluginTemplates.config};


c.paths.rnv.pluginTemplates.dirs={rnv:c.paths.rnv.pluginTemplates.dir};

customPluginTemplates=(_c$files$project$conf=c.files.project.config)==null?void 0:(_c$files$project$conf2=_c$files$project$conf.paths)==null?void 0:_c$files$project$conf2.pluginTemplates;
missingDeps=_parsePluginTemplateDependencies(c,customPluginTemplates);if(!
missingDeps.length){_context4.next=20;break;}
dependencies=c.files.project.package.dependencies;
hasPackageChanged=false;
missingDeps.forEach(function(dep){
var plugin=getMergedPlugin(c,dep);
if(plugin){
hasPackageChanged=true;
dependencies[dep]=plugin.version;
}else{

}
});if(!


hasPackageChanged){_context4.next=19;break;}
_updatePackage(c,{dependencies:dependencies});
(0,_logger.logInfo)('Found missing dependency scopes. INSTALLING...');_context4.next=15;return _regenerator.default.awrap(
(0,_npmUtils.installPackageDependencies)(c));case 15:_context4.next=17;return _regenerator.default.awrap(
loadPluginTemplates(c));case 17:_context4.next=20;break;case 19:

missingDeps.forEach(function(npmDep){
(0,_logger.logWarning)("Plugin scope "+npmDep+" does not exists in package.json.");
});case 20:return _context4.abrupt("return",


true);case 21:case"end":return _context4.stop();}}},null,null,null,Promise);};exports.loadPluginTemplates=loadPluginTemplates;


var _parsePluginTemplateDependencies=function _parsePluginTemplateDependencies(c,customPluginTemplates){var scope=arguments.length>2&&arguments[2]!==undefined?arguments[2]:'root';
(0,_logger.logTask)('_parsePluginTemplateDependencies',"scope:"+scope);
var missingDeps=[];
if(customPluginTemplates){
Object.keys(customPluginTemplates).forEach(function(k){
var val=customPluginTemplates[k];
if(val.npm){var _c$files$project$pack2,_c$files$project$pack3;
var npmDep=((_c$files$project$pack2=c.files.project.package)==null?void 0:_c$files$project$pack2.dependencies[val.npm])||((_c$files$project$pack3=
c.files.project.package)==null?void 0:_c$files$project$pack3.devDependencies[val.npm]);

if(npmDep){
var ptPath;
if(npmDep.startsWith('file:')){
ptPath=_path.default.join(
c.paths.project.dir,
npmDep.replace('file:',''),
val.path||'');

}else{

ptPath=(0,_resolve.doResolve)(val.npm)+"/"+val.path;
}

var ptConfig=_path.default.join(
ptPath,
_constants.RENATIVE_CONFIG_PLUGINS_NAME);

c.paths.rnv.pluginTemplates.dirs[k]=ptPath;
if((0,_fileutils.fsExistsSync)(ptConfig)){
c.files.rnv.pluginTemplates.configs[k]=(0,_fileutils.readObjectSync)(
ptConfig);

_parsePluginTemplateDependencies(c,
c.files.rnv.pluginTemplates.configs[k].pluginTemplateDependencies,
k);
}else{
(0,_logger.logWarning)("Plugin scope "+val.npm+" is not installed yet.");
}
}else{

missingDeps.push(val.npm);
}
}
});
}
return missingDeps;
};

var getCleanRegExString=function getCleanRegExString(str){return str.
replace(/\(/g,'\\(').
replace(/\)/g,'\\)').
replace(/\^/g,'\\^').
replace(/\?/g,'\\?').
replace(/\|/g,'\\|').
replace(/\*/g,'\\*').
replace(/\|/g,'\\|').
replace(/\[/g,'\\[').
replace(/\]/g,'\\]').
replace(/\{/g,'\\{').
replace(/\}/g,'\\}').
replace(/\+/g,'\\+').
replace(/ /g,' {1,}');};

var _overridePlugin=function _overridePlugin(c,pluginsPath,dir){
var source=_path.default.resolve(pluginsPath,dir,'overrides');
var dest=(0,_resolve.doResolve)(dir,false);
if(!dest)return;

var plugin=getMergedPlugin(c,dir);
var flavourSource;
if(plugin){
flavourSource=_path.default.resolve(
pluginsPath,
dir,"overrides@"+
plugin.version);

}

if(flavourSource&&(0,_fileutils.fsExistsSync)(flavourSource)){
(0,_fileutils.copyFolderContentsRecursiveSync)(flavourSource,dest,false);
}else if((0,_fileutils.fsExistsSync)(source)){
(0,_fileutils.copyFolderContentsRecursiveSync)(source,dest,false);



}else{
(0,_logger.logDebug)("Your plugin configuration has no override path "+
(0,_logger.chalk)().white(
source)+". skipping folder override action");


}

var overridePath=_path.default.resolve(pluginsPath,dir,"overrides@"+plugin.version+".json");
if(!(0,_fileutils.fsExistsSync)(overridePath)){
overridePath=_path.default.resolve(pluginsPath,dir,'overrides.json');
}
var overrideConfig=(0,_fileutils.readObjectSync)(overridePath);
var overrides=overrideConfig==null?void 0:overrideConfig.overrides;
if(overrides){
Object.keys(overrides).forEach(function(k){
var ovDir=_path.default.join(dest,k);
var override=overrides[k];
if((0,_fileutils.fsExistsSync)(ovDir)){
if((0,_fileutils.fsLstatSync)(ovDir).isDirectory()){
(0,_logger.logWarning)(
'overrides.json: Directories not supported yet. specify path to actual file');

}else{
overrideFileContents(ovDir,override,overridePath);
}
}
});
}
};

var overrideFileContents=function overrideFileContents(dest,override){var overridePath=arguments.length>2&&arguments[2]!==undefined?arguments[2]:'';
var fileToFix=(0,_fileutils.fsReadFileSync)(dest).toString();
var foundRegEx=false;
var failTerms=[];
Object.keys(override).forEach(function(fk){
var regEx=new RegExp(""+getCleanRegExString(fk),'g');
var count=(fileToFix.match(regEx)||[]).length;

var overrided=override[fk];
var regEx2=new RegExp(getCleanRegExString(overrided),'g');
var count2=(fileToFix.match(regEx2)||[]).length;
if(!count){
if(!count2){
failTerms.push(fk);
}else{
foundRegEx=true;
}
}else{
foundRegEx=true;
fileToFix=fileToFix.replace(regEx,override[fk]);
}
});
if(!foundRegEx){
failTerms.forEach(function(term){
(0,_logger.logWarning)("No Match found in "+(0,_logger.chalk)().red(
dest)+" for expression: "+
(0,_logger.chalk)().red(term)+".\nConsider update or removal of "+
(0,_logger.chalk)().white(overridePath));
});
}
(0,_fileutils.fsWriteFileSync)(dest,fileToFix);
};exports.overrideFileContents=overrideFileContents;

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

(0,_npmUtils.installPackageDependencies)(c));case 3:_context5.next=5;return _regenerator.default.awrap(
overrideTemplatePlugins(c));case 5:_context5.next=7;return _regenerator.default.awrap(
_checkForPluginDependencies(c));case 7:case"end":return _context5.stop();}}},null,null,null,Promise);};exports.installPackageDependenciesAndPlugins=installPackageDependenciesAndPlugins;


var _getPluginConfiguration=function _getPluginConfiguration(c,pluginName){
var renativePluginPath;
try{
renativePluginPath=require.resolve(pluginName+"/renative.plugin.json",{paths:[c.paths.project.dir]});
}catch(_unused){

}

if(renativePluginPath){
return(0,_fileutils.readObjectSync)(renativePluginPath);
}
return null;
};

var _checkForPluginDependencies=function _checkForPluginDependencies(c){var toAdd,install,answer;return _regenerator.default.async(function _checkForPluginDependencies$(_context6){while(1){switch(_context6.prev=_context6.next){case 0:
toAdd={};
Object.keys(c.buildConfig.plugins).forEach(function(pluginName){
var renativePluginConfig=_getPluginConfiguration(c,pluginName);

if(renativePluginConfig!=null&&renativePluginConfig.plugins){

Object.keys(renativePluginConfig.plugins).forEach(function(p){var _c$buildConfig$plugin5;
if(!c.buildConfig.plugins[p]&&((_c$buildConfig$plugin5=c.buildConfig.plugins[pluginName].plugins)==null?void 0:_c$buildConfig$plugin5[p])!==null){
(0,_logger.logWarning)("Plugin "+p+" is not installed yet.");
toAdd[p]=renativePluginConfig.plugins[p];
c.buildConfig.plugins[p]=renativePluginConfig.plugins[p];
}
});
}
});if(!

Object.keys(toAdd).length){_context6.next=20;break;}

install=false;if(
c.program.ci){_context6.next=11;break;}_context6.next=7;return _regenerator.default.awrap(
(0,_prompt.inquirerPrompt)({
type:'confirm',
message:"Install "+Object.keys(toAdd).join(', ')+"?",
warningMessage:"One or more dependencies are not installed: "+(0,_logger.chalk)().white(Object.keys(toAdd).join(', '))}));case 7:answer=_context6.sent;

install=answer.confirm;_context6.next=13;break;case 11:

(0,_logger.logWarning)('CI detected. Automatically installing dependencies');
install=true;case 13:if(!


install){_context6.next=20;break;}
c.files.project.config.plugins=_objectSpread(_objectSpread({},
c.files.project.config.plugins),
toAdd);

(0,_configManager.writeRenativeConfigFile)(c,c.paths.project.config,c.files.project.config);_context6.next=18;return _regenerator.default.awrap(
configurePlugins(c));case 18:_context6.next=20;return _regenerator.default.awrap(
installPackageDependenciesAndPlugins(c));case 20:case"end":return _context6.stop();}}},null,null,null,Promise);};




var overrideTemplatePlugins=function overrideTemplatePlugins(c){var rnvPluginsDirs,appPluginDirs,appBasePluginDir;return _regenerator.default.async(function overrideTemplatePlugins$(_context7){while(1){switch(_context7.prev=_context7.next){case 0:
(0,_logger.logTask)('overrideTemplatePlugins');

rnvPluginsDirs=c.paths.rnv.pluginTemplates.dirs;
appPluginDirs=c.paths.appConfig.pluginDirs;
appBasePluginDir=c.paths.project.appConfigBase.pluginsDir;
parsePlugins(c,c.platform,function(plugin,pluginPlat,key){var _plugin$_scopes;
if(plugin!=null&&(_plugin$_scopes=plugin._scopes)!=null&&_plugin$_scopes.length){
plugin._scopes.forEach(function(pluginScope){
var pluginOverridePath=rnvPluginsDirs[pluginScope];
if(pluginOverridePath){
_overridePlugin(c,pluginOverridePath,key);
}
});
}

if(appBasePluginDir){
_overridePlugin(c,appBasePluginDir,key);
}
if(appPluginDirs){
for(var k=0;k<appPluginDirs.length;k++){
_overridePlugin(c,appPluginDirs[k],key);
}
}
},true);return _context7.abrupt("return",
true);case 6:case"end":return _context7.stop();}}},null,null,null,Promise);};exports.overrideTemplatePlugins=overrideTemplatePlugins;


var copyTemplatePluginsSync=function copyTemplatePluginsSync(c){
var platform=c.platform;
var destPath=_path.default.join((0,_common.getAppFolder)(c));

(0,_logger.logTask)('copyTemplatePluginsSync',"("+destPath+")");


parsePlugins(c,platform,function(plugin,pluginPlat,key){
var objectInject=(0,_toConsumableArray2.default)(c.configPropsInjects);
if(plugin.props){
Object.keys(plugin.props).forEach(function(v){
objectInject.push({
pattern:"{{props."+v+"}}",
override:plugin.props[v]});

});
}

var sourcePathRnvPlugin=(0,_common.getBuildsFolder)(
c,
platform,
_path.default.join(c.paths.rnv.pluginTemplates.dir,key));

(0,_fileutils.copyFolderContentsRecursiveSync)(sourcePathRnvPlugin,destPath,true,false,false,objectInject);


var sourcePath3=(0,_common.getBuildsFolder)(
c,
platform,
_path.default.join(c.paths.project.appConfigBase.dir,"plugins/"+key));

(0,_fileutils.copyFolderContentsRecursiveSync)(sourcePath3,destPath,true,false,false,objectInject);


var sourcePath3secLegacy=(0,_common.getBuildsFolder)(
c,
platform,
_path.default.join(
c.paths.workspace.project.appConfigBase.dir_LEGACY,"plugins/"+
key));


(0,_fileutils.copyFolderContentsRecursiveSync)(sourcePath3secLegacy,destPath,true,false,false,objectInject);


var sourcePath3sec=(0,_common.getBuildsFolder)(
c,
platform,
_path.default.join(
c.paths.workspace.project.appConfigBase.dir,"plugins/"+
key));


(0,_fileutils.copyFolderContentsRecursiveSync)(sourcePath3sec,destPath,true,false,false,objectInject);

if((0,_fileutils.fsExistsSync)(sourcePath3secLegacy)){
(0,_logger.logWarning)("Path: "+(0,_logger.chalk)().red(sourcePath3secLegacy)+" is DEPRECATED.\n    Move your files to: "+
(0,_logger.chalk)().white(sourcePath3sec)+" instead");
}


var sourcePath2=(0,_common.getBuildsFolder)(
c,
platform,
_path.default.join(c.paths.appConfig.dir,"plugins/"+key));

(0,_fileutils.copyFolderContentsRecursiveSync)(sourcePath2,destPath,true,false,false,objectInject);


var sourcePath2sec=(0,_common.getBuildsFolder)(
c,
platform,
_path.default.join(c.paths.workspace.appConfig.dir,"plugins/"+key));

(0,_fileutils.copyFolderContentsRecursiveSync)(sourcePath2sec,destPath,true,false,false,objectInject);


Object.keys(c.paths.rnv.pluginTemplates.dirs).forEach(function(pathKey){
if(pathKey!=='rnv'){
var pluginTemplatePath=c.paths.rnv.pluginTemplates.dirs[pathKey];

var sourcePath4sec=(0,_common.getBuildsFolder)(
c,
platform,
_path.default.join(pluginTemplatePath,key));

(0,_fileutils.copyFolderContentsRecursiveSync)(sourcePath4sec,destPath,true,false,false,objectInject);
}
});
});
};exports.copyTemplatePluginsSync=copyTemplatePluginsSync;

var sanitizePluginPath=function sanitizePluginPath(str,name,mandatory,options){
var newStr=str;
try{
if(str!=null&&str.replace){
newStr=str.replace('{{PLUGIN_ROOT}}',(0,_resolve.doResolve)(name,mandatory,options));
}
}catch(e){

}
return newStr;
};exports.sanitizePluginPath=sanitizePluginPath;

var includesPluginPath=function includesPluginPath(str){
if(str!=null&&str.includes){
return str.includes('{{PLUGIN_ROOT}}');
}
return false;
};exports.includesPluginPath=includesPluginPath;

var getLocalRenativePlugin=function getLocalRenativePlugin(){return{
version:'file:../packages/renative',
webpack:{
modulePaths:[],
moduleAliases:{
renative:{
projectPath:'packages/renative'}}}};};exports.getLocalRenativePlugin=getLocalRenativePlugin;
//# sourceMappingURL=index.js.map