var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.runAppleLog=exports.archiveXcodeProject=exports.exportXcodeProject=exports.configureXcodeProject=exports.copyAppleAssets=exports.runCocoaPods=exports.getAppFolderName=exports.packageBundleForXcode=exports.buildXcodeProject=exports.runXcodeProject=exports.generateChecksum=void 0;var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _toConsumableArray2=_interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));

var _path=_interopRequireDefault(require("path"));
var _child_process=_interopRequireDefault(require("child_process"));
var _inquirer=_interopRequireDefault(require("inquirer"));
var _crypto=_interopRequireDefault(require("crypto"));
var _fileutils=require("../core/systemManager/fileutils");







var _exec=require("../core/systemManager/exec");
var _deviceManager=require("./deviceManager");
var _fastlane=require("./fastlane");
var _common=require("../core/common");




var _engineManager=require("../core/engineManager");
var _resolve=require("../core/systemManager/resolve");
var _platformManager=require("../core/platformManager");
var _projectManager=require("../core/projectManager");





var _constants=require("../core/constants");
var _plistParser=require("./plistParser");




var _xcschemeParser=require("./xcschemeParser");
var _podfileParser=require("./podfileParser");
var _xcodeParser=require("./xcodeParser");
var _swiftParser=require("./swiftParser");
var _logger=require("../core/systemManager/logger");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 generateChecksum=function generateChecksum(str,algorithm,encoding){return _crypto.default.
createHash(algorithm||'md5').
update(str,'utf8').
digest(encoding||'hex');};exports.generateChecksum=generateChecksum;

var checkIfPodsIsRequired=function checkIfPodsIsRequired(c){var appFolder,podChecksumPath,podChecksum,podContentChecksum;return _regenerator.default.async(function checkIfPodsIsRequired$(_context){while(1){switch(_context.prev=_context.next){case 0:
appFolder=(0,_common.getAppFolder)(c,c.platform);
podChecksumPath=_path.default.join(appFolder,'Podfile.checksum');if(
(0,_fileutils.fsExistsSync)(podChecksumPath)){_context.next=4;break;}return _context.abrupt("return",true);case 4:
podChecksum=(0,_fileutils.fsReadFileSync)(podChecksumPath).toString();
podContentChecksum=generateChecksum(
(0,_fileutils.fsReadFileSync)(_path.default.join(appFolder,'Podfile')).toString());if(!(


podChecksum!==podContentChecksum)){_context.next=9;break;}
(0,_logger.logDebug)('runCocoaPods:isMandatory');return _context.abrupt("return",
true);case 9:

(0,_logger.logInfo)(
'Pods do not seem like they need to be updated. If you want to update them manually run the same command with "-u" parameter');return _context.abrupt("return",

false);case 11:case"end":return _context.stop();}}},null,null,null,Promise);};


var updatePodsChecksum=function updatePodsChecksum(c){
(0,_logger.logTask)('updatePodsChecksum');
var appFolder=(0,_common.getAppFolder)(c,c.platform);
var podChecksumPath=_path.default.join(appFolder,'Podfile.checksum');
var podContentChecksum=generateChecksum(
(0,_fileutils.fsReadFileSync)(_path.default.join(appFolder,'Podfile')).toString());

if((0,_fileutils.fsExistsSync)(podChecksumPath)){
var existingContent=(0,_fileutils.fsReadFileSync)(podChecksumPath).toString();
if(existingContent!==podContentChecksum){
(0,_logger.logDebug)("updatePodsChecksum:"+podContentChecksum);
return(0,_fileutils.fsWriteFileSync)(podChecksumPath,podContentChecksum);
}
return true;
}
(0,_logger.logDebug)("updatePodsChecksum:"+podContentChecksum);
return(0,_fileutils.fsWriteFileSync)(podChecksumPath,podContentChecksum);
};

var runCocoaPods=function runCocoaPods(c){var appFolder,podsRequired,s,isGenericError;return _regenerator.default.async(function runCocoaPods$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:
(0,_logger.logTask)('runCocoaPods',"forceUpdate:"+!!c.program.updatePods);

appFolder=(0,_common.getAppFolder)(c);if(

(0,_fileutils.fsExistsSync)(appFolder)){_context2.next=4;break;}return _context2.abrupt("return",
Promise.reject("Location "+appFolder+" does not exists!"));case 4:_context2.t0=

c.program.updatePods;if(_context2.t0){_context2.next=9;break;}_context2.next=8;return _regenerator.default.awrap(checkIfPodsIsRequired(c));case 8:_context2.t0=_context2.sent;case 9:podsRequired=_context2.t0;if(!

podsRequired){_context2.next=28;break;}if(
(0,_exec.commandExistsSync)('pod')){_context2.next=13;break;}throw(
new Error(
'Cocoapods not installed. Please run `sudo gem install cocoapods`'));case 13:_context2.prev=13;_context2.next=16;return _regenerator.default.awrap(




(0,_exec.executeAsync)(c,'pod install',{
cwd:appFolder,
env:process.env}));case 16:_context2.next=26;break;case 18:_context2.prev=18;_context2.t1=_context2["catch"](13);


s=(_context2.t1==null?void 0:_context2.t1.toString)?_context2.t1.toString():'';
isGenericError=s.includes('No provisionProfileSpecifier configured')||
s.includes('TypeError:')||
s.includes('ReferenceError:')||
s.includes('find gem cocoapods');if(!
isGenericError){_context2.next=24;break;}return _context2.abrupt("return",new Error("pod install failed with:\n "+s));case 24:
(0,_logger.logWarning)("pod install is not enough! Let's try pod update! Error:\n "+
s);return _context2.abrupt("return",

(0,_exec.executeAsync)(c,'pod update',{
cwd:appFolder,
env:process.env}).

then(function(){return updatePodsChecksum(c);}).
catch(function(er){return Promise.reject(er);}));case 26:


updatePodsChecksum(c);return _context2.abrupt("return",
true);case 28:case"end":return _context2.stop();}}},null,null,[[13,18]],Promise);};exports.runCocoaPods=runCocoaPods;



var copyAppleAssets=function copyAppleAssets(c,platform,appFolderName){return new Promise(function(resolve){
(0,_logger.logTask)('copyAppleAssets');
if(!(0,_platformManager.isPlatformActive)(c,platform,resolve))return;

var appFolder=(0,_common.getAppFolder)(c);


(0,_fileutils.fsWriteFileSync)(_path.default.join(appFolder,'main.jsbundle'),'{}');
(0,_fileutils.mkdirSync)(_path.default.join(appFolder,'assets'));
(0,_fileutils.mkdirSync)(_path.default.join(appFolder,appFolderName+"/images"));

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

var runXcodeProject=function runXcodeProject(c){var appPath,device,scheme,runScheme,bundleIsDev,bundleAssets,p,devicesArr,run,selectedDevice,devices,_await$inquirer$promp,sim,_devices,_await$inquirer$promp2,_sim;return _regenerator.default.async(function runXcodeProject$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:
(0,_logger.logTask)('runXcodeProject',"target:"+c.runtime.target);

appPath=(0,_common.getAppFolder)(c,c.platform);
device=c.program.device;
scheme=(0,_common.getConfigProp)(c,c.platform,'scheme');
runScheme=(0,_common.getConfigProp)(c,c.platform,'runScheme');
bundleIsDev=(0,_common.getConfigProp)(c,c.platform,'bundleIsDev')===true;
bundleAssets=(0,_common.getConfigProp)(c,c.platform,'bundleAssets')===true;if(


scheme){_context3.next=9;break;}return _context3.abrupt("return",
Promise.reject("Missing scheme in platforms."+
(0,_logger.chalk)().yellow(
c.platform)+" in your "+
(0,_logger.chalk)().white(
c.paths.appConfig.config)+"! Check example config for more info:  "+
(0,_logger.chalk)().grey(
'https://github.com/pavjacko/renative/blob/master/appConfigs/helloworld/renative.json')+" "));case 9:if(!(





device===true)){_context3.next=15;break;}_context3.next=12;return _regenerator.default.awrap(
(0,_deviceManager.getAppleDevices)(c,false,true));case 12:devicesArr=_context3.sent;_context3.next=19;break;case 15:if(!(
c.runtime.target===true)){_context3.next=19;break;}_context3.next=18;return _regenerator.default.awrap(
(0,_deviceManager.getAppleDevices)(c,true,false));case 18:devicesArr=_context3.sent;case 19:if(!(


device===true)){_context3.next=44;break;}if(!(
devicesArr.length===1)){_context3.next=25;break;}
(0,_logger.logSuccess)("Found one device connected! device name: "+
(0,_logger.chalk)().white(
devicesArr[0].name)+" udid: "+
(0,_logger.chalk)().white(devicesArr[0].udid));

if(devicesArr[0].udid){
p="--device --udid "+devicesArr[0].udid;
c.runtime.targetUDID=devicesArr[0].udid;
}else{
p="--device "+devicesArr[0].name;
}_context3.next=42;break;case 25:if(!(
devicesArr.length>1)){_context3.next=41;break;}
run=function run(selectedDevice){
(0,_logger.logDebug)("Selected device: "+
JSON.stringify(
selectedDevice,
null,
3));


c.runtime.targetUDID=selectedDevice.udid;
if(selectedDevice.udid){
p="--device --udid "+selectedDevice.udid;
}else{
p="--device "+selectedDevice.name;
}

(0,_logger.logDebug)("RN params: "+p);

if(bundleAssets){
(0,_logger.logDebug)('Assets will be bundled');
return packageBundleForXcode(
c,
bundleIsDev).
then(function(){return _checkLockAndExec(c,appPath,scheme,runScheme,p);});
}
return _checkLockAndExec(c,appPath,scheme,runScheme,p);
};if(!(

c.runtime.target!==true)){_context3.next=32;break;}
selectedDevice=devicesArr.find(
function(d){return d.name===c.runtime.target;});if(!

selectedDevice){_context3.next=31;break;}return _context3.abrupt("return",
run(selectedDevice));case 31:

(0,_logger.logWarning)("Could not find device "+c.runtime.target);case 32:


devices=devicesArr.map(function(v){return{
name:v.name+" | "+v.icon+" | v: "+(0,_logger.chalk)().green(
v.version)+" | udid: "+
(0,_logger.chalk)().grey(v.udid)+(
v.isDevice?(0,_logger.chalk)().red(' (device)'):''),

value:v};});_context3.next=35;return _regenerator.default.awrap(


_inquirer.default.prompt({
name:'sim',
message:'Select the device you want to launch on',
type:'list',
choices:devices}));case 35:_await$inquirer$promp=_context3.sent;sim=_await$inquirer$promp.sim;if(!


sim){_context3.next=39;break;}return _context3.abrupt("return",
run(sim));case 39:_context3.next=42;break;case 41:return _context3.abrupt("return",


Promise.reject("No "+c.platform+" devices connected!"));case 42:_context3.next=59;break;case 44:if(!

device){_context3.next=48;break;}
p="--device "+device;_context3.next=59;break;case 48:if(!(
c.runtime.target===true)){_context3.next=58;break;}
_devices=devicesArr.map(function(v){return{
name:v.name+" | "+v.icon+" | v: "+(0,_logger.chalk)().green(
v.version)+" | udid: "+
(0,_logger.chalk)().grey(v.udid)+(
v.isDevice?(0,_logger.chalk)().red(' (device)'):''),

value:v};});_context3.next=52;return _regenerator.default.awrap(


_inquirer.default.prompt({
name:'sim',
message:'Select the device you want to launch on',
type:'list',
choices:_devices}));case 52:_await$inquirer$promp2=_context3.sent;_sim=_await$inquirer$promp2.sim;

c.runtime.target=_sim.name;
p="--simulator "+c.runtime.target.replace(/(\s+)/g,'\\$1');_context3.next=59;break;case 58:

p="--simulator "+c.runtime.target.replace(/(\s+)/g,'\\$1');case 59:if(!


p){_context3.next=63;break;}if(!








bundleAssets){_context3.next=62;break;}return _context3.abrupt("return",
packageBundleForXcode(c,bundleIsDev).
then(function(){return _checkLockAndExec(c,appPath,scheme,runScheme,p);}));case 62:return _context3.abrupt("return",

_checkLockAndExec(c,appPath,scheme,runScheme,p));case 63:return _context3.abrupt("return",

Promise.reject('Missing options for react-native command!'));case 64:case"end":return _context3.stop();}}},null,null,null,Promise);};exports.runXcodeProject=runXcodeProject;


var _checkLockAndExec=function _checkLockAndExec(c,appPath,scheme,runScheme,p){var cmd,isDeviceLocked,isDeviceNotRegistered,_await$inquirer$promp3,confirm,isDevelopmentTeamMissing,_c$paths$appConfig,loc,_await$inquirer$promp4,_confirm,isAutomaticSigningDisabled,isProvisioningMissing;return _regenerator.default.async(function _checkLockAndExec$(_context4){while(1){switch(_context4.prev=_context4.next){case 0:
(0,_logger.logTask)('_checkLockAndExec',"scheme:"+scheme+" runScheme:"+runScheme);
cmd="node "+(0,_resolve.doResolve)(
'react-native')+"/local-cli/cli.js run-ios --project-path "+
appPath+" --scheme "+scheme+" --configuration "+runScheme+" "+p;_context4.prev=2;return _context4.abrupt("return",



(0,_exec.executeAsync)(c,cmd));case 6:_context4.prev=6;_context4.t0=_context4["catch"](2);if(!(

_context4.t0&&_context4.t0.includes)){_context4.next=45;break;}
isDeviceLocked=_context4.t0.includes('ERROR:DEVICE_LOCKED');if(!
isDeviceLocked){_context4.next=14;break;}_context4.next=13;return _regenerator.default.awrap(
_inquirer.default.prompt({
message:'Unlock your device and press ENTER',
type:'confirm',
name:'confirm'}));case 13:return _context4.abrupt("return",

(0,_exec.executeAsync)(c,cmd));case 14:

isDeviceNotRegistered=_context4.t0.includes(
"doesn't include the currently selected device");if(!

isDeviceNotRegistered){_context4.next=26;break;}
(0,_logger.logError)(_context4.t0);
(0,_logger.logWarning)(
c.platform+" DEVICE: "+(0,_logger.chalk)().white(
c.runtime.target)+" with UDID: "+
(0,_logger.chalk)().white(
c.runtime.targetUDID)+" is not included in your provisionong profile in TEAM: "+
(0,_logger.chalk)().white(
(0,_common.getConfigProp)(c,c.platform,'teamID')));_context4.next=20;return _regenerator.default.awrap(


_inquirer.default.prompt({
name:'confirm',
message:'Do you want to register it?',
type:'confirm'}));case 20:_await$inquirer$promp3=_context4.sent;confirm=_await$inquirer$promp3.confirm;if(!

confirm){_context4.next=26;break;}_context4.next=25;return _regenerator.default.awrap(
(0,_fastlane.registerDevice)(c));case 25:return _context4.abrupt("return",
Promise.reject('Updated. Re-run your last command'));case 26:





isDevelopmentTeamMissing=_context4.t0.includes(
'requires a development team. Select a development team');if(!

isDevelopmentTeamMissing){_context4.next=39;break;}
loc="./appConfigs/"+
c.runtime.appId+"/renative.json:{ \"platforms\": { \""+
c.platform+"\": { \"teamID\": \".....\"";
(0,_logger.logError)(_context4.t0);
(0,_logger.logWarning)("You need specify the development team if you want to run app on "+
c.platform+" device. this can be set manually in "+
(0,_logger.chalk)().white(loc)+"\n  You can find correct teamID in the URL of your apple developer account: "+
(0,_logger.chalk)().white(
'https://developer.apple.com/account/#/overview/YOUR-TEAM-ID'));_context4.next=33;return _regenerator.default.awrap(

_inquirer.default.prompt({
name:'confirm',
message:"Type in your Apple Team ID to be used (will be saved to "+((_c$paths$appConfig=c.paths.appConfig)==null?void 0:_c$paths$appConfig.config)+")",
type:'input'}));case 33:_await$inquirer$promp4=_context4.sent;_confirm=_await$inquirer$promp4.confirm;if(!

_confirm){_context4.next=39;break;}_context4.next=38;return _regenerator.default.awrap(
_setDevelopmentTeam(c,_confirm));case 38:return _context4.abrupt("return",
Promise.reject('Updated. Re-run your last command'));case 39:





isAutomaticSigningDisabled=_context4.t0.includes(
'Automatic signing is disabled and unable to generate a profile');if(!

isAutomaticSigningDisabled){_context4.next=42;break;}return _context4.abrupt("return",
_handleProvisioningIssues(
c,_context4.t0,

"Your iOS App Development provisioning profiles don't match. under manual signing mode"));case 42:


isProvisioningMissing=_context4.t0.includes(
'requires a provisioning profile');if(!

isProvisioningMissing){_context4.next=45;break;}return _context4.abrupt("return",
_handleProvisioningIssues(
c,_context4.t0,

'Your iOS App requires a provisioning profile'));case 45:return _context4.abrupt("return",




Promise.reject(_context4.t0+"\n\n"+

(0,_logger.chalk)().green('SUGGESTION:')+"\n\n"+

(0,_logger.chalk)().yellow('STEP 1:')+"\nOpen xcode workspace at: "+
(0,_logger.chalk)().white(appPath+"/RNVApp.xcworkspace")+"\n\n"+

(0,_logger.chalk)().yellow('STEP 2:')+"\n"+
(0,_logger.chalk)().white('Run app and observe any extra errors')+"\n\n"+

(0,_logger.chalk)().yellow('IF ALL HOPE IS LOST:')+"\nRaise new issue and copy this SUMMARY box output at:\n"+

(0,_logger.chalk)().white('https://github.com/pavjacko/renative/issues')+"\nand we will try to help!\n\n"));case 46:case"end":return _context4.stop();}}},null,null,[[2,6]],Promise);};






var _handleProvisioningIssues=function _handleProvisioningIssues(c,e,msg){var provisioningStyle,isProvAutomatic,proAutoText,fixCommand,workspacePath,_await$inquirer$promp5,confirmAuto;return _regenerator.default.async(function _handleProvisioningIssues$(_context5){while(1){switch(_context5.prev=_context5.next){case 0:
provisioningStyle=(0,_common.getConfigProp)(c,c.platform,'provisioningStyle');

isProvAutomatic=provisioningStyle==='Automatic';
proAutoText=isProvAutomatic?
'':
(0,_logger.chalk)().white('[4]>')+" Switch to automatic signing for appId: "+
c.runtime.appId+" , platform: "+
c.platform+", scheme: "+c.runtime.scheme;
fixCommand="rnv crypto updateProfile -p "+c.platform+" -s "+c.runtime.scheme;
workspacePath=(0,_logger.chalk)().white(
(0,_common.getAppFolder)(c,c.platform)+"/RNVApp.xcworkspace");

(0,_logger.logError)(e);
(0,_logger.logWarning)(msg+". To fix try:\n"+
(0,_logger.chalk)().white(
'[1]>')+" Configure your certificates, provisioning profiles correctly manually\n"+

(0,_logger.chalk)().white('[2]>')+" Try to generate matching profiles with "+(0,_logger.chalk)().white(
fixCommand)+" (you need correct priviledges in apple developer portal)\n"+

(0,_logger.chalk)().white(
'[3]>')+" Open generated project in Xcode: "+

workspacePath+" and debug from there (Sometimes this helps for the first-time builds)\n"+

proAutoText);if(!
isProvAutomatic){_context5.next=9;break;}return _context5.abrupt("return",false);case 9:_context5.next=11;return _regenerator.default.awrap(
_inquirer.default.prompt({
name:'confirmAuto',
message:'Switch to automatic signing?',
type:'confirm'}));case 11:_await$inquirer$promp5=_context5.sent;confirmAuto=_await$inquirer$promp5.confirmAuto;if(!

confirmAuto){_context5.next=17;break;}_context5.next=16;return _regenerator.default.awrap(
_setAutomaticSigning(c));case 16:return _context5.abrupt("return",
Promise.reject('Updated. Re-run your last command'));case 17:case"end":return _context5.stop();}}},null,null,null,Promise);};






var _setAutomaticSigning=function _setAutomaticSigning(c){var _c$files$appConfig,_c$files$appConfig$co,_c$files$appConfig$co2,_c$files$appConfig$co3,_c$files$appConfig$co4;var scheme,_c$paths$appConfig2;return _regenerator.default.async(function _setAutomaticSigning$(_context6){while(1){switch(_context6.prev=_context6.next){case 0:
(0,_logger.logTask)("_setAutomaticSigning:"+c.platform);

scheme=(_c$files$appConfig=c.files.appConfig)==null?void 0:(_c$files$appConfig$co=_c$files$appConfig.config)==null?void 0:(_c$files$appConfig$co2=_c$files$appConfig$co.platforms)==null?void 0:(_c$files$appConfig$co3=_c$files$appConfig$co2[c.platform])==null?void 0:(_c$files$appConfig$co4=_c$files$appConfig$co3.buildSchemes)==null?void 0:_c$files$appConfig$co4[
c.runtime.scheme];if(!

scheme){_context6.next=8;break;}
scheme.provisioningStyle='Automatic';
(0,_fileutils.writeFileSync)(c.paths.appConfig.config,c.files.appConfig.config);
(0,_logger.logSuccess)("Succesfully updated "+c.paths.appConfig.config);_context6.next=9;break;case 8:return _context6.abrupt("return",

Promise.reject("Failed to update "+((_c$paths$appConfig2=
c.paths.appConfig)==null?void 0:_c$paths$appConfig2.config)+".\"platforms\": { \""+
c.platform+"\": { buildSchemes: { \""+
c.runtime.scheme+"\" ... Object is null. Try update file manually"));case 9:case"end":return _context6.stop();}}},null,null,null,Promise);};




var _setDevelopmentTeam=function _setDevelopmentTeam(c,teamID){var _c$files$appConfig2,_c$files$appConfig2$c,_c$files$appConfig2$c2;var plat,_c$paths$appConfig3;return _regenerator.default.async(function _setDevelopmentTeam$(_context7){while(1){switch(_context7.prev=_context7.next){case 0:
(0,_logger.logTask)("_setDevelopmentTeam:"+teamID);

plat=(_c$files$appConfig2=c.files.appConfig)==null?void 0:(_c$files$appConfig2$c=_c$files$appConfig2.config)==null?void 0:(_c$files$appConfig2$c2=_c$files$appConfig2$c.platforms)==null?void 0:_c$files$appConfig2$c2[c.platform];if(!
plat){_context7.next=8;break;}
plat.teamID=teamID;
(0,_fileutils.writeFileSync)(c.paths.appConfig.config,c.files.appConfig.config);
(0,_logger.logSuccess)("Succesfully updated "+c.paths.appConfig.config);_context7.next=9;break;case 8:return _context7.abrupt("return",

Promise.reject("Failed to update "+((_c$paths$appConfig3=
c.paths.appConfig)==null?void 0:_c$paths$appConfig3.config)+".\"platforms\": { \""+
c.platform+"\" ... Object is null. Try update file manually"));case 9:case"end":return _context7.stop();}}},null,null,null,Promise);};





var composeXcodeArgsFromCLI=function composeXcodeArgsFromCLI(string){
var spacesReplaced=string.replace(
/\s(?=(?:[^'"`]*(['"`])[^'"`]*\1)*[^'"`]*$)/g,
'&&&');

var keysAndValues=spacesReplaced.split('&&&');
var unescapedValues=keysAndValues.map(function(s){return s.
replace(/'/g,'').
replace(/"/g,'').
replace(/\\/g,'');});

return unescapedValues;
};

var buildXcodeProject=function buildXcodeProject(c){var platform,appFolderName,runScheme,destinationPlatform,scheme,appPath,buildPath,allowProvisioningUpdates,ignoreLogs,ps,p,args;return _regenerator.default.async(function buildXcodeProject$(_context8){while(1){switch(_context8.prev=_context8.next){case 0:
(0,_logger.logTask)('buildXcodeProject');

platform=c.platform;

appFolderName=getAppFolderName(c,platform);
runScheme=(0,_common.getConfigProp)(c,platform,'runScheme','Debug');

destinationPlatform='';_context8.t0=
c.platform;_context8.next=_context8.t0===
_constants.TVOS?8:_context8.t0===







_constants.IOS?10:12;break;case 8:if(c.program.device){destinationPlatform='tvOS';}else{destinationPlatform='tvOS Simulator';}return _context8.abrupt("break",13);case 10:
if(c.program.device){
destinationPlatform='iOS';
}else{
destinationPlatform='iOS Simulator';
}return _context8.abrupt("break",13);case 12:



(0,_logger.logError)("platform "+c.platform+" not supported");case 13:


scheme=(0,_common.getConfigProp)(c,platform,'scheme');
appPath=(0,_common.getAppFolder)(c);
buildPath=_path.default.join(appPath,"build/"+scheme);
allowProvisioningUpdates=(0,_common.getConfigProp)(
c,
platform,
'allowProvisioningUpdates',
true);

ignoreLogs=(0,_common.getConfigProp)(c,platform,'ignoreLogs');
ps='';
if(c.program.xcodebuildArgs){
ps=c.program.xcodebuildArgs;
}
p=[];

if(!ps.includes('-workspace')){
p.push('-workspace');
p.push(appPath+"/"+appFolderName+".xcworkspace");
}
if(!ps.includes('-scheme')){
p.push('-scheme');
p.push(scheme);
}
if(!ps.includes('-configuration')){
p.push('-configuration');
p.push(runScheme);
}
if(!ps.includes('-derivedDataPath')){
p.push('-derivedDataPath');
p.push(buildPath);
}
if(!ps.includes('-destination')){
p.push('-destination');
p.push("platform="+destinationPlatform+",name="+c.runtime.target);
}

p.push('build');

if(allowProvisioningUpdates&&!ps.includes('-allowProvisioningUpdates')){p.push('-allowProvisioningUpdates');}
if(ignoreLogs&&!ps.includes('-quiet'))p.push('-quiet');

(0,_logger.logTask)('buildXcodeProject','STARTING xcodebuild BUILD...');if(!(

c.buildConfig.platforms[platform].runScheme==='Release')){_context8.next=34;break;}_context8.next=33;return _regenerator.default.awrap(
(0,_exec.executeAsync)(c,"xcodebuild "+ps+" "+p.join(' ')));case 33:
(0,_logger.logSuccess)("Your Build is located in "+
(0,_logger.chalk)().cyan(buildPath)+" .");case 34:



args=ps!==''?[].concat((0,_toConsumableArray2.default)(composeXcodeArgsFromCLI(ps)),p):p;

(0,_logger.logDebug)('xcodebuild args',args);return _context8.abrupt("return",

(0,_exec.executeAsync)('xcodebuild',{rawCommand:{args:args}}).then(function(){
(0,_logger.logSuccess)("Your Build is located in "+(0,_logger.chalk)().cyan(buildPath)+" .");
}));case 37:case"end":return _context8.stop();}}},null,null,null,Promise);};exports.buildXcodeProject=buildXcodeProject;


var archiveXcodeProject=function archiveXcodeProject(c){
(0,_logger.logTask)('archiveXcodeProject');var
platform=c.platform;

var appFolderName=getAppFolderName(c,platform);
var runScheme=(0,_common.getConfigProp)(c,platform,'runScheme','Debug');
var sdk=(0,_common.getConfigProp)(c,platform,'sdk');
if(!sdk){
if(platform===_constants.IOS)sdk='iphoneos';
if(platform===_constants.TVOS)sdk='appletvos';
if(platform===_constants.MACOS)sdk='macosx';
}
var sdkArr=[sdk];

var appPath=(0,_common.getAppFolder)(c);
var exportPath=_path.default.join(appPath,'release');

var scheme=(0,_common.getConfigProp)(c,platform,'scheme');
var allowProvisioningUpdates=(0,_common.getConfigProp)(
c,
platform,
'allowProvisioningUpdates',
true);

var ignoreLogs=(0,_common.getConfigProp)(c,platform,'ignoreLogs');
var exportPathArchive=exportPath+"/"+scheme+".xcarchive";
var ps='';
if(c.program.xcodebuildArchiveArgs){
ps=c.program.xcodebuildArchiveArgs;
}
var p=[];

if(!ps.includes('-workspace')){
p.push('-workspace');
p.push(appPath+"/"+appFolderName+".xcworkspace");
}
if(!ps.includes('-scheme')){
p.push('-scheme');
p.push(scheme);
}
if(!ps.includes('-sdk')){
p.push('-sdk');
p.push.apply(p,sdkArr);
}
if(!ps.includes('-configuration')){
p.push('-configuration');
p.push(runScheme);
}
p.push('archive');
if(!ps.includes('-archivePath')){
p.push('-archivePath');
p.push(exportPathArchive);
}

if(allowProvisioningUpdates&&!ps.includes('-allowProvisioningUpdates')){p.push('-allowProvisioningUpdates');}
if(ignoreLogs&&!ps.includes('-quiet'))p.push('-quiet');


(0,_logger.logTask)('archiveXcodeProject','STARTING xcodebuild ARCHIVE...');


var args=ps!==''?[].concat((0,_toConsumableArray2.default)(composeXcodeArgsFromCLI(ps)),p):p;

(0,_logger.logDebug)('xcodebuild args',args);

return(0,_exec.executeAsync)('xcodebuild',{rawCommand:{args:args}}).then(function(){
(0,_logger.logSuccess)("Your Archive is located in "+(0,_logger.chalk)().cyan(exportPath)+" .");
});
};exports.archiveXcodeProject=archiveXcodeProject;

var exportXcodeProject=function exportXcodeProject(c){var platform,appPath,exportPath,scheme,allowProvisioningUpdates,ignoreLogs,ps,p;return _regenerator.default.async(function exportXcodeProject$(_context9){while(1){switch(_context9.prev=_context9.next){case 0:
(0,_logger.logTask)('exportXcodeProject');

platform=c.platform;_context9.next=4;return _regenerator.default.awrap(

archiveXcodeProject(c));case 4:

appPath=(0,_common.getAppFolder)(c);
exportPath=_path.default.join(appPath,'release');

scheme=(0,_common.getConfigProp)(c,platform,'scheme');
allowProvisioningUpdates=(0,_common.getConfigProp)(
c,
platform,
'allowProvisioningUpdates',
true);

ignoreLogs=(0,_common.getConfigProp)(c,platform,'ignoreLogs');

ps='';
if(c.program.xcodebuildExportArgs){
ps=c.program.xcodebuildExportArgs;
}
p=['-exportArchive'];

if(!ps.includes('-archivePath')){
p.push("-archivePath "+exportPath+"/"+scheme+".xcarchive");
}
if(!ps.includes('-exportOptionsPlist')){
p.push("-exportOptionsPlist "+appPath+"/exportOptions.plist");
}
if(!ps.includes('-exportPath')){
p.push("-exportPath "+exportPath);
}

if(allowProvisioningUpdates&&!ps.includes('-allowProvisioningUpdates')){p.push('-allowProvisioningUpdates');}
if(ignoreLogs&&!ps.includes('-quiet'))p.push('-quiet');

(0,_logger.logDebug)('running',p);

(0,_logger.logTask)('exportXcodeProject','STARTING xcodebuild EXPORT...');return _context9.abrupt("return",

(0,_exec.executeAsync)(c,"xcodebuild "+p.join(' ')).then(function(){
(0,_logger.logSuccess)("Your IPA is located in "+(0,_logger.chalk)().cyan(exportPath)+" .");
}));case 20:case"end":return _context9.stop();}}},null,null,null,Promise);};exports.exportXcodeProject=exportXcodeProject;


var packageBundleForXcode=function packageBundleForXcode(c){var isDev=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;
(0,_logger.logTask)('packageBundleForXcode');

var args=[
'bundle',
'--platform',
'ios',
'--dev',
isDev,
'--assets-dest',"platformBuilds/"+
c.runtime.appId+"_"+c.platform,
'--entry-file',
c.buildConfig.platforms[c.platform].entryFile+".js",
'--bundle-output',
(0,_common.getAppFolder)(c,c.platform)+"/main.jsbundle"];


if(c.program.info){
args.push('--verbose');
}

return(0,_exec.executeAsync)(c,"node "+(0,_resolve.doResolve)(
'react-native')+"/local-cli/cli.js "+
args.join(' ')+" --config=metro.config.js",{env:_objectSpread({},(0,_engineManager.generateEnvVars)(c))});
};exports.packageBundleForXcode=packageBundleForXcode;

var getAppFolderName=function getAppFolderName(c,platform){
var projectFolder=(0,_common.getConfigProp)(c,platform,'projectFolder');
if(projectFolder){
return projectFolder;
}
return platform===_constants.IOS?'RNVApp':'RNVAppTVOS';
};exports.getAppFolderName=getAppFolderName;


var runAppleLog=function runAppleLog(c){return new Promise(function(){
(0,_logger.logTask)('runAppleLog');
var filter=c.program.filter||'RNV';
var child=_child_process.default.execFile(
'xcrun',
[
'simctl',
'spawn',
'booted',
'log',
'stream',
'--predicate',"eventMessage contains \""+
filter+"\""],

{stdio:'inherit',customFds:[0,1,2]});


child.stdout.on('data',function(data){
var d=data.toString();
if(d.toLowerCase().includes('error')){
(0,_logger.logRaw)((0,_logger.chalk)().red(d));
}else if(d.toLowerCase().includes('success')){
(0,_logger.logRaw)((0,_logger.chalk)().green(d));
}else{
(0,_logger.logRaw)(d);
}
});
});};exports.runAppleLog=runAppleLog;

var configureXcodeProject=function configureXcodeProject(c){var device,platform,bundlerIp,appFolder,appFolderName,bundleAssets,embeddedFontSourcesCheck,tId;return _regenerator.default.async(function configureXcodeProject$(_context10){while(1){switch(_context10.prev=_context10.next){case 0:
(0,_logger.logTask)('configureXcodeProject');
device=c.program.device;
platform=c.platform;
bundlerIp=device?(0,_common.getIP)():'localhost';
appFolder=(0,_common.getAppFolder)(c);
c.runtime.platformBuildsProjectPath=appFolder+"/RNVApp.xcworkspace";
appFolderName=getAppFolderName(c,platform);
bundleAssets=(0,_common.getConfigProp)(c,platform,'bundleAssets')===true;

c.pluginConfigiOS={
podfileInject:'',
staticFrameworks:[],
staticPodDefinition:'',
exportOptions:'',
embeddedFonts:[],
embeddedFontSources:[],
ignoreProjectFonts:[],
pluginAppDelegateImports:'',
pluginAppDelegateMethods:'',
appDelegateMethods:{
application:{
didFinishLaunchingWithOptions:[],
applicationDidBecomeActive:[],
open:[],
supportedInterfaceOrientationsFor:[],
didReceiveRemoteNotification:[],
didFailToRegisterForRemoteNotificationsWithError:[],
didReceive:[],
didRegister:[],
didRegisterForRemoteNotificationsWithDeviceToken:[],
continue:[]},

userNotificationCenter:{
willPresent:[]}},


podfileSources:[]};




















embeddedFontSourcesCheck=[];
(0,_projectManager.parseFonts)(c,function(font,dir){
if(font.includes('.ttf')||font.includes('.otf')){
var key=font.split('.')[0];
var includedFonts=(0,_common.getConfigProp)(c,c.platform,'includedFonts');
if(
includedFonts&&(
includedFonts.includes('*')||includedFonts.includes(key)))
{
var fontSource=_path.default.join(dir,font);
if((0,_fileutils.fsExistsSync)(fontSource)){
var fontFolder=_path.default.join(appFolder,'fonts');
(0,_fileutils.mkdirSync)(fontFolder);
var fontDest=_path.default.join(fontFolder,font);
(0,_fileutils.copyFileSync)(fontSource,fontDest);

if(
!c.pluginConfigiOS.ignoreProjectFonts.includes(font)&&
!embeddedFontSourcesCheck.includes(font))
{
c.pluginConfigiOS.embeddedFontSources.push(fontSource);
embeddedFontSourcesCheck.push(font);
}

if(!c.pluginConfigiOS.embeddedFonts.includes(font)){
c.pluginConfigiOS.embeddedFonts.push(font);
}
}else{
(0,_logger.logWarning)("Font "+
(0,_logger.chalk)().white(
fontSource)+" doesn't exist! Skipping.");


}
}
}
});


tId=(0,_common.getConfigProp)(c,platform,'teamID');
if(device&&(!tId||tId==='')){
(0,_logger.logError)("You're missing teamID in your "+
(0,_logger.chalk)().white(
c.paths.appConfig.config)+" => .platforms."+
platform+".teamID . you will not be able to build "+platform+" app for device!");

}_context10.next=15;return _regenerator.default.awrap(

(0,_projectManager.copyAssetsFolder)(c,platform));case 15:_context10.next=17;return _regenerator.default.awrap(
copyAppleAssets(c,platform,appFolderName));case 17:_context10.next=19;return _regenerator.default.awrap(
(0,_swiftParser.parseAppDelegate)(
c,
platform,
appFolder,
appFolderName,
bundleAssets,
bundlerIp));case 19:_context10.next=21;return _regenerator.default.awrap(

(0,_plistParser.parseExportOptionsPlist)(c,platform));case 21:_context10.next=23;return _regenerator.default.awrap(
(0,_xcschemeParser.parseXcscheme)(c,platform));case 23:_context10.next=25;return _regenerator.default.awrap(
(0,_podfileParser.parsePodFile)(c,platform));case 25:_context10.next=27;return _regenerator.default.awrap(
(0,_plistParser.parseEntitlementsPlist)(c,platform));case 27:_context10.next=29;return _regenerator.default.awrap(
(0,_plistParser.parseInfoPlist)(c,platform));case 29:_context10.next=31;return _regenerator.default.awrap(
(0,_projectManager.copyBuildsFolder)(c,platform));case 31:_context10.next=33;return _regenerator.default.awrap(
runCocoaPods(c));case 33:_context10.next=35;return _regenerator.default.awrap(
(0,_xcodeParser.parseXcodeProject)(c,platform));case 35:return _context10.abrupt("return",
true);case 36:case"end":return _context10.stop();}}},null,null,null,Promise);};exports.configureXcodeProject=configureXcodeProject;
//# sourceMappingURL=index.js.map