var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.parseXcodeProject=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));
var _path=_interopRequireDefault(require("path"));
var _common=require("../core/common");





var _fileutils=require("../core/systemManager/fileutils");
var _resolve=require("../core/systemManager/resolve");
var _logger=require("../core/systemManager/logger");
var _prompt=require("../cli/prompt");
var _constants=require("../core/constants");
var _pluginManager=require("../core/pluginManager");
var _index=require("./index");
var _provisionParser=require("./provisionParser");


var parseXcodeProject=function parseXcodeProject(c){var platform,result,eligibleProfile,_await$inquirerPrompt,autoFix,w;return _regenerator.default.async(function parseXcodeProject$(_context){while(1){switch(_context.prev=_context.next){case 0:
(0,_logger.logTask)('parseXcodeProject');
platform=c.platform;

c.runtime.xcodeProj={};
c.runtime.xcodeProj.provisioningStyle=(0,_common.getConfigProp)(
c,
platform,
'provisioningStyle',
'Automatic');

c.runtime.xcodeProj.deploymentTarget=(0,_common.getConfigProp)(
c,
platform,
'deploymentTarget',
'10.0');

c.runtime.xcodeProj.provisionProfileSpecifier=(0,_common.getConfigProp)(
c,
platform,
'provisionProfileSpecifier');

c.runtime.xcodeProj.codeSignIdentity=(0,_common.getConfigProp)(
c,
platform,
'codeSignIdentity',
'iPhone Developer');

c.runtime.xcodeProj.systemCapabilities=(0,_common.getConfigProp)(
c,
platform,
'systemCapabilities');

c.runtime.xcodeProj.runScheme=(0,_common.getConfigProp)(c,platform,'runScheme');
c.runtime.xcodeProj.teamID=(0,_common.getConfigProp)(c,platform,'teamID');
c.runtime.xcodeProj.id=(0,_common.getConfigProp)(c,platform,'id');
c.runtime.xcodeProj.appId=(0,_common.getAppId)(c,platform);if(!(


c.runtime.xcodeProj.provisioningStyle!=='Automatic'&&
!c.runtime.xcodeProj.provisionProfileSpecifier)){_context.next=27;break;}_context.next=15;return _regenerator.default.awrap(

(0,_provisionParser.parseProvisioningProfiles)(c));case 15:result=_context.sent;



if(result==null?void 0:result.eligable){
result.eligable.forEach(function(v){
var bundleId=v.Entitlements['application-identifier'];

if(
bundleId===
c.runtime.xcodeProj.teamID+"."+c.runtime.xcodeProj.id)
{
eligibleProfile=v;
}
});
}if(!


eligibleProfile){_context.next=25;break;}_context.next=20;return _regenerator.default.awrap(
(0,_prompt.inquirerPrompt)({
type:'confirm',
name:'autoFix',
message:"Found following eligible provisioning profile on your system: "+eligibleProfile.Entitlements['application-identifier']+". Do you want ReNative to fix your app confing?",
warningMessage:
'No provisionProfileSpecifier configured in appConfig despite setting provisioningStyle to manual'}));case 20:_await$inquirerPrompt=_context.sent;autoFix=_await$inquirerPrompt.autoFix;

if(autoFix){
c.runtime.xcodeProj.provisionProfileSpecifier=eligibleProfile.Name;
c.files.appConfig.config.platforms[platform].buildSchemes[
c.program.scheme].
provisionProfileSpecifier=eligibleProfile.Name;
(0,_fileutils.writeFileSync)(
c.paths.appConfig.config,
c.files.appConfig.config);

}_context.next=27;break;case 25:

w='Your build config has provisioningStyle set to manual but no provisionProfileSpecifier configured in appConfig and no available provisioning profiles availiable for';
(0,_logger.logWarning)(
w+" "+c.runtime.xcodeProj.id);case 27:_context.next=29;return _regenerator.default.awrap(




_parseXcodeProject(c,platform));case 29:case"end":return _context.stop();}}},null,null,null,Promise);};exports.parseXcodeProject=parseXcodeProject;


var _parseXcodeProject=function _parseXcodeProject(c,platform){return new Promise(function(resolve){
(0,_logger.logTask)('_parseXcodeProject');

var xcode=require((0,_resolve.doResolve)('xcode'));

var appFolder=(0,_common.getAppFolder)(c);
var appFolderName=(0,_index.getAppFolderName)(c,platform);
var projectPath=_path.default.join(
appFolder,
appFolderName+".xcodeproj/project.pbxproj");

var xcodeProj=xcode.project(projectPath);
xcodeProj.parse(function(){var _c$runtime$xcodeProj=








c.runtime.xcodeProj,provisioningStyle=_c$runtime$xcodeProj.provisioningStyle,deploymentTarget=_c$runtime$xcodeProj.deploymentTarget,provisionProfileSpecifier=_c$runtime$xcodeProj.provisionProfileSpecifier,codeSignIdentity=_c$runtime$xcodeProj.codeSignIdentity,systemCapabilities=_c$runtime$xcodeProj.systemCapabilities,teamID=_c$runtime$xcodeProj.teamID,appId=_c$runtime$xcodeProj.appId;

if(c.runtime.xcodeProj.teamID){
xcodeProj.updateBuildProperty('DEVELOPMENT_TEAM',teamID);
}else{
xcodeProj.updateBuildProperty('DEVELOPMENT_TEAM','""');
}

xcodeProj.addTargetAttribute(
'ProvisioningStyle',
provisioningStyle);

xcodeProj.addBuildProperty('CODE_SIGN_STYLE',provisioningStyle);
xcodeProj.updateBuildProperty('PRODUCT_BUNDLE_IDENTIFIER',appId);

if(platform===_constants.IOS){
xcodeProj.updateBuildProperty(
'IPHONEOS_DEPLOYMENT_TARGET',
deploymentTarget);

}else if(platform===_constants.TVOS){
xcodeProj.updateBuildProperty(
'TVOS_DEPLOYMENT_TARGET',
deploymentTarget);

}

if(provisionProfileSpecifier){
xcodeProj.updateBuildProperty(
'PROVISIONING_PROFILE_SPECIFIER',"\""+
provisionProfileSpecifier+"\"");

}

xcodeProj.updateBuildProperty(
'CODE_SIGN_IDENTITY',"\""+
codeSignIdentity+"\"");

xcodeProj.updateBuildProperty(
'"CODE_SIGN_IDENTITY[sdk=iphoneos*]"',"\""+
codeSignIdentity+"\"");















if(systemCapabilities){
var sysCapObj={};
Object.keys(systemCapabilities).forEach(function(sk){
var val=systemCapabilities[sk];
sysCapObj[sk]={enabled:val===true?1:0};
});

xcodeProj.addTargetAttribute('SystemCapabilities',sysCapObj);
}

var xcodeprojObj1=(0,_common.getConfigProp)(
c,
c.platform,
'xcodeproj');


if(xcodeprojObj1==null?void 0:xcodeprojObj1.sourceFiles){
xcodeprojObj1.sourceFiles.forEach(function(v){
var filePath=_path.default.join(appFolder,v);
if((0,_fileutils.fsExistsSync)(filePath)){
xcodeProj.addSourceFile(
filePath,
null,
'200132F21F6BF9CF00450340');

}else{
(0,_logger.logWarning)("You are trying to inject native file which does not exists: "+
(0,_logger.chalk)().red(filePath)+". Skipping.");

}
});
}


(0,_pluginManager.parsePlugins)(c,platform,function(plugin,pluginPlat){
var xcodeprojObj=(0,_common.getFlavouredProp)(
c,
pluginPlat,
'xcodeproj');

if(xcodeprojObj){
if(xcodeprojObj.resourceFiles){
xcodeprojObj.resourceFiles.forEach(function(v){
xcodeProj.addResourceFile(_path.default.join(appFolder,v));
});
}
if(xcodeprojObj.sourceFiles){
xcodeprojObj.sourceFiles.forEach(function(v){

xcodeProj.addSourceFile(
v,
null,
'200132F21F6BF9CF00450340');

});
}
if(xcodeprojObj.headerFiles){
xcodeprojObj.headerFiles.forEach(function(v){
xcodeProj.addHeaderFile(
v,
null,
'200132F21F6BF9CF00450340');

});
}
if(xcodeprojObj.buildPhases){
xcodeprojObj.buildPhases.forEach(function(v){
xcodeProj.addBuildPhase(
[],
'PBXShellScriptBuildPhase',
'ShellScript',
null,
{
shellPath:v.shellPath||'/bin/sh',
shellScript:v.shellScript,
inputPaths:v.inputPaths||[
'"$(SRCROOT)/$(BUILT_PRODUCTS_DIR)/$(INFOPLIST_PATH)"']});



});
}
if(xcodeprojObj.frameworks){
Object.keys(xcodeprojObj.frameworks).forEach(function(k){
var fPath;
var opts;
if(k.startsWith('./')){
fPath=_path.default.join(
appFolder,
k.replace('./',''));

opts={
customFramework:true,
embed:true,
link:true};

}else{
fPath=_path.default.join(
'System/Library/Frameworks',
k);

opts={
embed:true};

}
xcodeProj.addFramework(fPath,opts);
});
}
if(xcodeprojObj.buildSettings){
Object.keys(xcodeprojObj.buildSettings).forEach(function(k){
xcodeProj.addToBuildSettings(
k,
xcodeprojObj.buildSettings[k]);

});
}
}
});



c.pluginConfigiOS.embeddedFontSources.forEach(function(v){
xcodeProj.addResourceFile(v,{variantGroup:false});
});

(0,_fileutils.fsWriteFileSync)(projectPath,xcodeProj.writeSync());
resolve();
});
});};
//# sourceMappingURL=xcodeParser.js.map