var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.parsePodFile=void 0;var _path=_interopRequireDefault(require("path"));
var _fs=_interopRequireDefault(require("fs"));
var _chalk=_interopRequireDefault(require("chalk"));
var _common=require("../../common");


















var _projectParser=require("../../projectTools/projectParser");
var _pluginTools=require("../../pluginTools");

var parsePodFile=function parsePodFile(c,platform){return new Promise(function(resolve,reject){var _c$buildConfig,_c$buildConfig$platfo,_c$buildConfig$platfo2,_c$buildConfig$platfo3;
(0,_common.logTask)("parsePodFileSync:"+platform);

var appFolder=(0,_common.getAppFolder)(c,platform);
var pluginSubspecs='';
var pluginInject='';


c.pluginConfigiOS.podfileInject='';
(0,_pluginTools.parsePlugins)(c,platform,function(plugin,pluginPlat,key){
if(pluginPlat.podName){
pluginInject+=_injectPod(pluginPlat.podName,pluginPlat,plugin,key);
}
if(pluginPlat.podNames){
pluginPlat.podNames.forEach(function(v){
pluginInject+=_injectPod(v,pluginPlat,plugin,key);
});
}

if(pluginPlat.reactSubSpecs){
pluginPlat.reactSubSpecs.forEach(function(v){
if(!pluginSubspecs.includes("'"+v+"'")){
pluginSubspecs+="  '"+v+"',\n";
}
});
}

if(pluginPlat.Podfile){var
injectLines=pluginPlat.Podfile.injectLines;

if(injectLines){
injectLines.forEach(function(v){
c.pluginConfigiOS.podfileInject+=v+"\n";
});
}
}
});


var reactCore=c.buildConfig?
c.buildConfig.reactCore:c.files.rnv.pluginTemplates.config.reactCore;
if(reactCore){
if(reactCore.ios.reactSubSpecs){
reactCore.ios.reactSubSpecs.forEach(function(v){
if(!pluginSubspecs.includes("'"+v+"'")){
pluginSubspecs+="  '"+v+"',\n";
}
});
}
}


var ignoreWarnings=(0,_common.getConfigProp)(c,platform,'ignoreWarnings');
var podWarnings=ignoreWarnings?'inhibit_all_warnings!':'';


c.pluginConfigiOS.podfileSources='';
var podfileSources=(_c$buildConfig=c.buildConfig)==null?void 0:(_c$buildConfig$platfo=_c$buildConfig.platforms)==null?void 0:(_c$buildConfig$platfo2=_c$buildConfig$platfo.ios)==null?void 0:(_c$buildConfig$platfo3=_c$buildConfig$platfo2.Podfile)==null?void 0:_c$buildConfig$platfo3.sources;
if(podfileSources&&podfileSources.length){
podfileSources.forEach(function(v){
c.pluginConfigiOS.podfileSources+="source '"+v+"'\n";
});
}


var deploymentTarget=(0,_common.getConfigProp)(c,platform,'deploymentTarget','10.0');
c.pluginConfigiOS.deploymentTarget=deploymentTarget;

(0,_common.writeCleanFile)(_path.default.join((0,_common.getAppTemplateFolder)(c,platform),'Podfile'),_path.default.join(appFolder,'Podfile'),[
{pattern:'{{PLUGIN_PATHS}}',override:pluginInject},
{pattern:'{{PLUGIN_SUBSPECS}}',override:pluginSubspecs},
{pattern:'{{PLUGIN_WARNINGS}}',override:podWarnings},
{pattern:'{{PLUGIN_PODFILE_INJECT}}',override:c.pluginConfigiOS.podfileInject},
{pattern:'{{PLUGIN_PODFILE_SOURCES}}',override:c.pluginConfigiOS.podfileSources},
{pattern:'{{PLUGIN_DEPLOYMENT_TARGET}}',override:c.pluginConfigiOS.deploymentTarget}]);

resolve();
});};exports.parsePodFile=parsePodFile;

var _injectPod=function _injectPod(podName,pluginPlat,plugin,key){
var pluginInject='';
var isNpm=plugin['no-npm']!==true;
if(isNpm){
var podPath=pluginPlat.path?"../../"+pluginPlat.path:"../../node_modules/"+key;
pluginInject+="  pod '"+podName+"', :path => '"+podPath+"'\n";
}else if(pluginPlat.git){
var commit=pluginPlat.commit?", :commit => '"+pluginPlat.commit+"'":'';
pluginInject+="  pod '"+podName+"', :git => '"+pluginPlat.git+"'"+commit+"\n";
}else if(pluginPlat.version){
pluginInject+="  pod '"+podName+"', '"+pluginPlat.version+"'\n";
}else{
pluginInject+="  pod '"+podName+"'\n";
}
return pluginInject;
};