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 _betterOpn=_interopRequireDefault(require("better-opn"));
var _ip=_interopRequireDefault(require("ip"));
var _path=_interopRequireDefault(require("path"));

var _common=require("../../common");






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












var _web=require("../../platformTools/web");
var _tizen=require("../../platformTools/tizen");
var _webos=require("../../platformTools/webos");
var _firefox=require("../../platformTools/firefox");
var _chromecast=require("../../platformTools/chromecast");
var _fileutils=require("../../systemTools/fileutils");
var _exec=require("../../systemTools/exec");
var _config=_interopRequireDefault(require("../../config"));
var _analytics=_interopRequireDefault(require("../../systemTools/analytics"));
var _sdkManager=require("../../platformTools/sdkManager");


var TASKS={};

var _configureHostedIfRequired=function _configureHostedIfRequired(c){var _c$paths,project,rnv;return _regenerator.default.async(function _configureHostedIfRequired$(_context){while(1){switch(_context.prev=_context.next){case 0:
(0,_logger.logTask)("_configureHostedIfRequired:"+c.platform);
if(_config.default.isWebHostEnabled){
(0,_logger.logDebug)('Running hosted build');_c$paths=
c.paths,project=_c$paths.project,rnv=_c$paths.rnv;
(0,_fileutils.copyFolderContentsRecursiveSync)(
_path.default.join(rnv.dir,'supportFiles','appShell'),
_path.default.join(
project.dir,
'platformBuilds',
c.runtime.appId+"_"+c.platform,
'public'));


(0,_fileutils.writeCleanFile)(
_path.default.join(rnv.dir,'supportFiles','appShell','index.html'),
_path.default.join(
project.dir,
'platformBuilds',
c.runtime.appId+"_"+c.platform,
'public',
'index.html'),

[
{
pattern:'{{DEV_SERVER}}',
override:"http://"+_ip.default.address()+":"+c.runtime.port}],

null,c);

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


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

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


if(_config.default.isWebHostEnabled&&hosted){
(0,_common.waitForWebpack)(c).
then(function(){return(0,_betterOpn.default)("http://"+c.runtime.localhost+":"+port+"/");}).
catch(_logger.logError);
}_context2.t0=

platform;_context2.next=_context2.t0===
_constants.WEB?8:_context2.t0===
_constants.TIZEN?8:_context2.t0===
_constants.WEBOS?8:_context2.t0===
_constants.TIZEN_MOBILE?8:_context2.t0===
_constants.TIZEN_WATCH?8:11;break;case 8:_context2.next=10;return _regenerator.default.awrap(
(0,_common.configureIfRequired)(c,platform));case 10:return _context2.abrupt("return",
(0,_web.runWeb)(c,platform,port));case 11:if(!

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


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


TASKS[_constants.TASK_START]=_taskStart;

var _taskRun=function _taskRun(c){var platform,port,target,hosted;return _regenerator.default.async(function _taskRun$(_context3){while(1){switch(_context3.prev=_context3.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);if(!(
_config.default.isWebHostEnabled&&hosted)){_context3.next=8;break;}
c.runtime.shouldOpenBrowser=true;return _context3.abrupt("return",
_taskStart(c));case 8:_context3.t0=

platform;_context3.next=_context3.t0===
_constants.WEB?11:_context3.t0===







_constants.TIZEN?18:_context3.t0===
_constants.TIZEN_MOBILE?18:_context3.t0===
_constants.TIZEN_WATCH?18:_context3.t0===






_constants.WEBOS?26:_context3.t0===






_constants.KAIOS?34:_context3.t0===
_constants.FIREFOX_OS?34:_context3.t0===
_constants.FIREFOX_TV?34:_context3.t0===





_constants.CHROMECAST?40:48;break;case 11:if(c.program.only){_context3.next=16;break;}_context3.next=14;return _regenerator.default.awrap((0,_common.cleanPlatformIfRequired)(c,platform));case 14:_context3.next=16;return _regenerator.default.awrap((0,_common.configureIfRequired)(c,platform));case 16:c.runtime.shouldOpenBrowser=true;return _context3.abrupt("return",(0,_web.runWeb)(c,platform,port,true));case 18:if(c.program.only){_context3.next=25;break;}_context3.next=21;return _regenerator.default.awrap((0,_common.cleanPlatformIfRequired)(c,platform));case 21:_context3.next=23;return _regenerator.default.awrap((0,_common.configureIfRequired)(c,platform));case 23:_context3.next=25;return _regenerator.default.awrap(_configureHostedIfRequired(c));case 25:return _context3.abrupt("return",(0,_tizen.runTizen)(c,platform,target));case 26:if(c.program.only){_context3.next=33;break;}_context3.next=29;return _regenerator.default.awrap((0,_common.cleanPlatformIfRequired)(c,platform));case 29:_context3.next=31;return _regenerator.default.awrap((0,_common.configureIfRequired)(c,platform));case 31:_context3.next=33;return _regenerator.default.awrap(_configureHostedIfRequired(c));case 33:return _context3.abrupt("return",(0,_webos.runWebOS)(c,platform,target));case 34:if(c.program.only){_context3.next=39;break;}_context3.next=37;return _regenerator.default.awrap((0,_common.cleanPlatformIfRequired)(c,platform));case 37:_context3.next=39;return _regenerator.default.awrap((0,_common.configureIfRequired)(c,platform));case 39:return _context3.abrupt("return",(0,_firefox.runFirefoxProject)(c,platform));case 40:if(
c.program.only){_context3.next=47;break;}_context3.next=43;return _regenerator.default.awrap(
(0,_common.cleanPlatformIfRequired)(c,platform));case 43:_context3.next=45;return _regenerator.default.awrap(
(0,_common.configureIfRequired)(c,platform));case 45:_context3.next=47;return _regenerator.default.awrap(
_configureHostedIfRequired(c));case 47:return _context3.abrupt("return",

(0,_chromecast.runChromecast)(c,platform,target));case 48:return _context3.abrupt("return",

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


TASKS[_constants.TASK_RUN]=_taskRun;

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

(0,_sdkManager.checkSdk)(c));case 4:_context4.t0=

platform;_context4.next=7;break;case 7:

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


TASKS[_constants.TASK_PACKAGE]=_taskPackage;

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

(0,_sdkManager.checkSdk)(c));case 4:_context5.t0=

platform;_context5.next=_context5.t0===
_constants.WEB?7:11;break;case 7:if(
c.program.only){_context5.next=10;break;}_context5.next=10;return _regenerator.default.awrap(
_taskBuild(c));case 10:return _context5.abrupt("return",

(0,_web.exportWeb)(c,platform));case 11:

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


TASKS[_constants.TASK_EXPORT]=_taskExport;

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

(0,_sdkManager.checkSdk)(c));case 4:_context6.t0=

platform;_context6.next=_context6.t0===
_constants.WEB?7:_context6.t0===
_constants.CHROMECAST?7:_context6.t0===




_constants.KAIOS?14:_context6.t0===
_constants.FIREFOX_OS?14:_context6.t0===
_constants.FIREFOX_TV?14:_context6.t0===




_constants.TIZEN?21:_context6.t0===
_constants.TIZEN_MOBILE?21:_context6.t0===
_constants.TIZEN_WATCH?21:_context6.t0===




_constants.WEBOS?28:35;break;case 7:_context6.next=9;return _regenerator.default.awrap((0,_common.cleanPlatformIfRequired)(c,platform));case 9:_context6.next=11;return _regenerator.default.awrap((0,_common.configureIfRequired)(c,platform));case 11:_context6.next=13;return _regenerator.default.awrap((0,_web.buildWeb)(c,platform));case 13:return _context6.abrupt("return");case 14:_context6.next=16;return _regenerator.default.awrap((0,_common.cleanPlatformIfRequired)(c,platform));case 16:_context6.next=18;return _regenerator.default.awrap((0,_common.configureIfRequired)(c,platform));case 18:_context6.next=20;return _regenerator.default.awrap((0,_firefox.buildFirefoxProject)(c,platform));case 20:return _context6.abrupt("return");case 21:_context6.next=23;return _regenerator.default.awrap((0,_common.cleanPlatformIfRequired)(c,platform));case 23:_context6.next=25;return _regenerator.default.awrap((0,_common.configureIfRequired)(c,platform));case 25:_context6.next=27;return _regenerator.default.awrap((0,_tizen.buildTizenProject)(c,platform));case 27:return _context6.abrupt("return");case 28:_context6.next=30;return _regenerator.default.awrap(
(0,_common.cleanPlatformIfRequired)(c,platform));case 30:_context6.next=32;return _regenerator.default.awrap(
(0,_common.configureIfRequired)(c,platform));case 32:_context6.next=34;return _regenerator.default.awrap(
(0,_webos.buildWebOSProject)(c,platform));case 34:return _context6.abrupt("return");case 35:


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


TASKS[_constants.TASK_BUILD]=_taskBuild;

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

platform;_context7.next=_context7.t0===
_constants.WEB?5:_context7.t0===




_constants.CHROMECAST?9:13;break;case 5:if(c.program.only){_context7.next=8;break;}_context7.next=8;return _regenerator.default.awrap(_taskBuild(c));case 8:return _context7.abrupt("return",(0,_web.deployWeb)(c,platform));case 9:if(
c.program.only){_context7.next=12;break;}_context7.next=12;return _regenerator.default.awrap(
_taskBuild(c));case 12:return _context7.abrupt("return",

(0,_web.deployWeb)(c,platform));case 13:if(

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



TASKS[_constants.TASK_DEPLOY]=_taskDeploy;

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

platform;_context8.next=_context8.t0===
_constants.WEB?5:_context8.t0===
_constants.TIZEN?5:6;break;case 5:return _context8.abrupt("return",
(0,_exec.executeAsync)(c,'npx weinre --boundHost -all-'));case 6:

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


TASKS[_constants.TASK_DEBUG]=_taskDebug;

var _taskLog=function _taskLog(c){return _regenerator.default.async(function _taskLog$(_context9){while(1){switch(_context9.prev=_context9.next){case 0:
(0,_logger.logTask)("_taskLog:"+c.platform);
switch(c.platform){
default:
(0,_common.logErrorPlatform)(c,c.platform);}case 2:case"end":return _context9.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$(_context10){while(1){switch(_context10.prev=_context10.next){case 0:
(0,_logger.logTask)("runTask:engine-rn-web:"+c.platform);_context10.next=3;return _regenerator.default.awrap(

(0,_platformTools.isPlatformSupported)(c));case 3:_context10.next=5;return _regenerator.default.awrap(
(0,_common.isBuildSchemeSupported)(c));case 5:_context10.next=7;return _regenerator.default.awrap(
(0,_sdkManager.checkSdk)(c));case 7:

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

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


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