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







var _resolve=require("../../resolve");
var _platformTools=require("../../platformTools");
var _logger=require("../../systemTools/logger");
var _constants=require("../../constants");








var _apple=require("../../platformTools/apple");






var _android=require("../../platformTools/android");






var _exec=require("../../systemTools/exec");
var _config=_interopRequireDefault(require("../../config"));
var _analytics=_interopRequireDefault(require("../../systemTools/analytics"));

var _bundler=require("../../platformTools/bundler");
var _sdkManager=require("../../platformTools/sdkManager");

var TASKS={};

var keepRNVRunning=false;

var waitForBundlerIfRequired=function waitForBundlerIfRequired(c){var bundleAssets;return _regenerator.default.async(function waitForBundlerIfRequired$(_context){while(1){switch(_context.prev=_context.next){case 0:
bundleAssets=(0,_common.getConfigProp)(c,c.platform,'bundleAssets');if(!(
bundleAssets===true)){_context.next=3;break;}return _context.abrupt("return");case 3:if(!

keepRNVRunning){_context.next=5;break;}return _context.abrupt("return",new Promise(function(){}));case 5:return _context.abrupt("return",
true);case 6:case"end":return _context.stop();}}},null,null,null,Promise);};


var _startBundlerIfRequired=function _startBundlerIfRequired(c){var bundleAssets,isRunning;return _regenerator.default.async(function _startBundlerIfRequired$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:
(0,_logger.logTask)("_startBundlerIfRequired:"+c.platform);
bundleAssets=(0,_common.getConfigProp)(c,c.platform,'bundleAssets');if(!(
bundleAssets===true)){_context2.next=4;break;}return _context2.abrupt("return");case 4:_context2.next=6;return _regenerator.default.awrap(

(0,_bundler.isBundlerActive)(c));case 6:isRunning=_context2.sent;if(
isRunning){_context2.next=14;break;}
_taskStart(c);
keepRNVRunning=true;_context2.next=12;return _regenerator.default.awrap(
(0,_bundler.waitForBundler)(c));case 12:_context2.next=16;break;case 14:_context2.next=16;return _regenerator.default.awrap(

(0,_common.confirmActiveBundler)(c));case 16:case"end":return _context2.stop();}}},null,null,null,Promise);};



var _taskStart=function _taskStart(c){var platform,port,hosted,startCmd;return _regenerator.default.async(function _taskStart$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:
platform=c.platform;
port=c.runtime.port;
hosted=c.program.hosted;

(0,_logger.logTask)("_taskStart:"+
platform+":"+port+":"+hosted+":"+_config.default.isWebHostEnabled);if(!


hosted){_context3.next=6;break;}return _context3.abrupt("return",
(0,_logger.logError)(
'This platform does not support hosted mode',
true));case 6:_context3.t0=



platform;_context3.next=_context3.t0===
_constants.IOS?9:_context3.t0===
_constants.TVOS?9:_context3.t0===
_constants.ANDROID?9:_context3.t0===
_constants.ANDROID_TV?9:_context3.t0===
_constants.ANDROID_WEAR?9:12;break;case 9:
startCmd="node "+(0,_resolve.doResolve)(
'react-native')+"/local-cli/cli.js start --port "+

c.runtime.port+" --config=configs/metro.config."+
c.platform+".js";

if(c.program.resetHard){
startCmd+=' --reset-cache';
}else if(c.program.reset&&c.command==='start'){
startCmd+=' --reset-cache';
}return _context3.abrupt("return",

(0,_exec.executeAsync)(c,startCmd,{stdio:'inherit',silent:true}));case 12:return _context3.abrupt("return",



(0,_common.logErrorPlatform)(c,platform));case 13:case"end":return _context3.stop();}}},null,null,null,Promise);};exports._taskStart=_taskStart;


TASKS[_constants.TASK_START]=_taskStart;

var _taskRun=function _taskRun(c){var platform,port,target,hosted,bundleAssets;return _regenerator.default.async(function _taskRun$(_context4){while(1){switch(_context4.prev=_context4.next){case 0:
platform=c.platform;
port=c.runtime.port;
target=c.runtime.target;
hosted=c.program.hosted;
(0,_logger.logTask)("_taskRun:"+platform+":"+port+":"+target+":"+hosted);

bundleAssets=(0,_common.getConfigProp)(c,c.platform,'bundleAssets',false);_context4.t0=


platform;_context4.next=_context4.t0===
_constants.IOS?9:_context4.t0===
_constants.TVOS?9:_context4.t0===











_constants.ANDROID?21:_context4.t0===
_constants.ANDROID_TV?21:_context4.t0===
_constants.ANDROID_WEAR?21:36;break;case 9:if(c.program.only){_context4.next=20;break;}_context4.next=12;return _regenerator.default.awrap((0,_common.cleanPlatformIfRequired)(c,platform));case 12:_context4.next=14;return _regenerator.default.awrap((0,_common.configureIfRequired)(c,platform));case 14:_context4.next=16;return _regenerator.default.awrap(_startBundlerIfRequired(c));case 16:_context4.next=18;return _regenerator.default.awrap((0,_apple.runXcodeProject)(c));case 18:if(!bundleAssets){(0,_logger.logSummary)('BUNDLER STARTED');}return _context4.abrupt("return",waitForBundlerIfRequired(c));case 20:return _context4.abrupt("return",(0,_apple.runXcodeProject)(c));case 21:if(
c.program.only){_context4.next=35;break;}_context4.next=24;return _regenerator.default.awrap(
(0,_common.cleanPlatformIfRequired)(c,platform));case 24:_context4.next=26;return _regenerator.default.awrap(
(0,_common.configureIfRequired)(c,platform));case 26:_context4.next=28;return _regenerator.default.awrap(
_startBundlerIfRequired(c));case 28:if(!(

(0,_common.getConfigProp)(c,platform,'bundleAssets')===true||
platform===_constants.ANDROID_WEAR)){_context4.next=31;break;}_context4.next=31;return _regenerator.default.awrap(

(0,_android.packageAndroid)(c,platform));case 31:_context4.next=33;return _regenerator.default.awrap(

(0,_android.runAndroid)(c,platform,target));case 33:
if(!bundleAssets){
(0,_logger.logSummary)('BUNDLER STARTED');
}return _context4.abrupt("return",
waitForBundlerIfRequired(c));case 35:return _context4.abrupt("return",

(0,_android.runAndroid)(c,platform,target));case 36:return _context4.abrupt("return",

(0,_common.logErrorPlatform)(c,platform));case 37:case"end":return _context4.stop();}}},null,null,null,Promise);};


TASKS[_constants.TASK_RUN]=_taskRun;


var _taskPackage=function _taskPackage(c){var platform,target;return _regenerator.default.async(function _taskPackage$(_context5){while(1){switch(_context5.prev=_context5.next){case 0:
(0,_logger.logTask)("_taskPackage:"+c.platform);
platform=c.platform;

target=c.program.target||c.files.workspace.config.defaultTargets[platform];_context5.t0=

platform;_context5.next=_context5.t0===
_constants.IOS?6:_context5.t0===
_constants.TVOS?6:_context5.t0===





_constants.ANDROID?12:_context5.t0===
_constants.ANDROID_TV?12:_context5.t0===
_constants.ANDROID_WEAR?12:20;break;case 6:if(c.program.only){_context5.next=11;break;}_context5.next=9;return _regenerator.default.awrap((0,_common.cleanPlatformIfRequired)(c,platform));case 9:_context5.next=11;return _regenerator.default.awrap((0,_common.configureIfRequired)(c,platform));case 11:return _context5.abrupt("return",(0,_apple.packageBundleForXcode)(c,platform));case 12:if(
c.program.only){_context5.next=19;break;}_context5.next=15;return _regenerator.default.awrap(
(0,_common.cleanPlatformIfRequired)(c,platform));case 15:_context5.next=17;return _regenerator.default.awrap(
(0,_common.configureIfRequired)(c,platform));case 17:_context5.next=19;return _regenerator.default.awrap(
(0,_android.configureGradleProject)(c,platform));case 19:return _context5.abrupt("return",

(0,_android.packageAndroid)(
c,
platform,
target,
platform===_constants.ANDROID_WEAR));case 20:


(0,_common.logErrorPlatform)(c,platform);return _context5.abrupt("return",
false);case 22:case"end":return _context5.stop();}}},null,null,null,Promise);};


TASKS[_constants.TASK_PACKAGE]=_taskPackage;


var _taskExport=function _taskExport(c){var platform;return _regenerator.default.async(function _taskExport$(_context6){while(1){switch(_context6.prev=_context6.next){case 0:
(0,_logger.logTask)("_taskExport:"+c.platform);
platform=c.platform;_context6.t0=

platform;_context6.next=_context6.t0===
_constants.IOS?5:_context6.t0===
_constants.TVOS?5:_context6.t0===




_constants.ANDROID?9:_context6.t0===
_constants.ANDROID_TV?9:_context6.t0===
_constants.ANDROID_WEAR?9:10;break;case 5:if(c.program.only){_context6.next=8;break;}_context6.next=8;return _regenerator.default.awrap(_taskPackage(c));case 8:return _context6.abrupt("return",(0,_apple.exportXcodeProject)(c,platform));case 9:return _context6.abrupt("return",
_taskBuild(c));case 10:

(0,_common.logErrorPlatform)(c,platform);case 11:case"end":return _context6.stop();}}},null,null,null,Promise);};


TASKS[_constants.TASK_EXPORT]=_taskExport;

var _taskBuild=function _taskBuild(c){var platform;return _regenerator.default.async(function _taskBuild$(_context7){while(1){switch(_context7.prev=_context7.next){case 0:
(0,_logger.logTask)("_taskBuild:"+c.platform);
platform=c.platform;_context7.t0=



platform;_context7.next=_context7.t0===
_constants.ANDROID?5:_context7.t0===
_constants.ANDROID_TV?5:_context7.t0===
_constants.ANDROID_WEAR?5:_context7.t0===






_constants.IOS?16:_context7.t0===
_constants.TVOS?16:21;break;case 5:_context7.next=7;return _regenerator.default.awrap((0,_common.cleanPlatformIfRequired)(c,platform));case 7:_context7.next=9;return _regenerator.default.awrap((0,_common.configureIfRequired)(c,platform));case 9:_context7.next=11;return _regenerator.default.awrap((0,_android.configureGradleProject)(c,platform));case 11:_context7.next=13;return _regenerator.default.awrap((0,_android.packageAndroid)(c,platform));case 13:_context7.next=15;return _regenerator.default.awrap((0,_android.buildAndroid)(c,platform));case 15:return _context7.abrupt("return");case 16:_context7.next=18;return _regenerator.default.awrap(
_taskPackage(c));case 18:_context7.next=20;return _regenerator.default.awrap(
(0,_apple.buildXcodeProject)(c,platform));case 20:return _context7.abrupt("return");case 21:


(0,_common.logErrorPlatform)(c,platform);case 22:case"end":return _context7.stop();}}},null,null,null,Promise);};


TASKS[_constants.TASK_BUILD]=_taskBuild;

var _taskDeploy=function _taskDeploy(c){var platform;return _regenerator.default.async(function _taskDeploy$(_context8){while(1){switch(_context8.prev=_context8.next){case 0:
(0,_logger.logTask)("_taskDeploy:"+c.platform);
platform=c.platform;_context8.t0=

platform;_context8.next=_context8.t0===
_constants.TVOS?5:_context8.t0===
_constants.IOS?5:_context8.t0===




_constants.ANDROID_TV?8:_context8.t0===
_constants.ANDROID_WEAR?8:_context8.t0===
_constants.ANDROID?8:11;break;case 5:if(c.program.only){_context8.next=7;break;}return _context8.abrupt("return",_taskExport(c));case 7:return _context8.abrupt("return");case 8:if(
c.program.only){_context8.next=10;break;}return _context8.abrupt("return",
_taskBuild(c));case 10:return _context8.abrupt("return");case 11:if(



c.program.only){_context8.next=14;break;}_context8.next=14;return _regenerator.default.awrap(
_taskExport(c));case 14:case"end":return _context8.stop();}}},null,null,null,Promise);};



TASKS[_constants.TASK_DEPLOY]=_taskDeploy;

var _taskDebug=function _taskDebug(c){var platform;return _regenerator.default.async(function _taskDebug$(_context9){while(1){switch(_context9.prev=_context9.next){case 0:
(0,_logger.logTask)("_taskDebug:"+c.platform);
platform=c.platform;

switch(platform){
default:
(0,_common.logErrorPlatform)(c,platform);}case 3:case"end":return _context9.stop();}}},null,null,null,Promise);};


TASKS[_constants.TASK_DEBUG]=_taskDebug;

var _taskLog=function _taskLog(c){return _regenerator.default.async(function _taskLog$(_context10){while(1){switch(_context10.prev=_context10.next){case 0:
(0,_logger.logTask)("_taskLog:"+c.platform);_context10.t0=
c.platform;_context10.next=_context10.t0===
_constants.ANDROID?4:_context10.t0===
_constants.ANDROID_TV?4:_context10.t0===
_constants.ANDROID_WEAR?4:_context10.t0===


_constants.IOS?7:_context10.t0===
_constants.TVOS?7:10;break;case 4:_context10.next=6;return _regenerator.default.awrap((0,_android.runAndroidLog)(c));case 6:return _context10.abrupt("return");case 7:_context10.next=9;return _regenerator.default.awrap(
(0,_apple.runAppleLog)(c));case 9:return _context10.abrupt("return");case 10:


(0,_common.logErrorPlatform)(c,c.platform);case 11:case"end":return _context10.stop();}}},null,null,null,Promise);};exports._taskLog=_taskLog;


TASKS[_constants.TASK_LOG]=_taskLog;


var runTask=function runTask(c,task){return _regenerator.default.async(function runTask$(_context11){while(1){switch(_context11.prev=_context11.next){case 0:
(0,_logger.logTask)("runTask:engine-rn:"+c.platform);_context11.next=3;return _regenerator.default.awrap(
(0,_platformTools.isPlatformSupported)(c));case 3:_context11.next=5;return _regenerator.default.awrap(
(0,_common.isBuildSchemeSupported)(c));case 5:_context11.next=7;return _regenerator.default.awrap(
(0,_sdkManager.checkSdk)(c));case 7:

_analytics.default.captureEvent({
type:task+"Project",
platform:c.platform});return _context11.abrupt("return",

TASKS[task](c));case 9:case"end":return _context11.stop();}}},null,null,null,Promise);};var _default=


{
runTask:runTask};exports.default=_default;
//# sourceMappingURL=index.js.map