var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.rnvLog=exports.rnvDeploy=exports.rnvExport=exports.rnvBuild=exports.rnvPackage=exports.rnvRun=exports.rnvDebug=exports.rnvStart=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));

var _chalk=_interopRequireDefault(require("chalk"));
var _openBrowser=_interopRequireDefault(require("react-dev-utils/openBrowser"));
var _ip=_interopRequireDefault(require("ip"));
var _path=_interopRequireDefault(require("path"));

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













var _constants=require("../constants");

















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






var _web=require("./web");
var _tizen=require("./tizen");
var _webos=require("./webos");
var _firefox=require("./firefox");
var _electron=require("./electron");



var _setupTools=_interopRequireDefault(require("../setupTools"));
var _android=require("./android");






var _fileutils=require("../systemTools/fileutils");
var _exec=require("../systemTools/exec");

var isRunningOnWindows=process.platform==='win32';






var rnvStart=function rnvStart(c){var platform,port,hosted,hostIp,startCmd;return _regenerator.default.async(function rnvStart$(_context){while(1){switch(_context.prev=_context.next){case 0:
platform=c.platform;
port=c.program.port||c.platformDefaults[platform]?c.platformDefaults[platform].defaultPort:null;
hosted=c.program.hosted;

(0,_common.logTask)("rnvStart:"+platform+":"+port);

if(_isWebHostEnabled(c,platform)&&hosted){
hostIp=isRunningOnWindows?'127.0.0.1':'0.0.0.0';
(0,_common.waitForWebpack)(c,port).
then(function(){return(0,_openBrowser.default)("http://"+hostIp+":"+port+"/");}).
catch(_common.logError);
}_context.t0=

platform;_context.next=_context.t0===
_constants.MACOS?8:_context.t0===
_constants.WINDOWS?8:_context.t0===


_constants.WEB?9:_context.t0===
_constants.TIZEN?9:_context.t0===
_constants.WEBOS?9:_context.t0===
_constants.TIZEN_MOBILE?9:_context.t0===
_constants.TIZEN_WATCH?9:12;break;case 8:return _context.abrupt("return",(0,_electron.runElectronDevServer)(c,platform,port));case 9:_context.next=11;return _regenerator.default.awrap(
(0,_common.configureIfRequired)(c,platform));case 11:return _context.abrupt("return",
(0,_web.runWebDevServer)(c,platform,port));case 12:if(!

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




if(c.program.reset){
startCmd='node ./node_modules/react-native/local-cli/cli.js start --reset-cache';
}else{
startCmd='node ./node_modules/react-native/local-cli/cli.js start';
}_context.next=17;return _regenerator.default.awrap(

(0,_exec.executeAsync)(c,startCmd,{stdio:'inherit',silent:true}));case 17:case"end":return _context.stop();}}});};exports.rnvStart=rnvStart;


var runWeinre=function runWeinre(c){return(0,_exec.executeAsync)(c,'npx weinre --boundHost -all-');};

var rnvDebug=function rnvDebug(c){return _regenerator.default.async(function rnvDebug$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:
(0,_common.logTask)("rnvDebug:"+c.platform);_context2.next=3;return _regenerator.default.awrap(

(0,_common.isPlatformSupported)(c));case 3:_context2.next=5;return _regenerator.default.awrap(
(0,_common.isBuildSchemeSupported)(c));case 5:_context2.next=7;return _regenerator.default.awrap(
runWeinre(c));case 7:case"end":return _context2.stop();}}});};exports.rnvDebug=rnvDebug;



var rnvRun=function rnvRun(c){return _regenerator.default.async(function rnvRun$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:
(0,_common.logTask)("rnvRun:"+c.platform);_context3.next=3;return _regenerator.default.awrap(

(0,_common.isPlatformSupported)(c));case 3:_context3.next=5;return _regenerator.default.awrap(
(0,_common.isBuildSchemeSupported)(c));case 5:_context3.next=7;return _regenerator.default.awrap(
_rnvRunWithPlatform(c));case 7:case"end":return _context3.stop();}}});};exports.rnvRun=rnvRun;


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

(0,_common.isPlatformSupported)(c));case 3:_context4.next=5;return _regenerator.default.awrap(
(0,_common.isBuildSchemeSupported)(c));case 5:_context4.next=7;return _regenerator.default.awrap(
_rnvPackageWithPlatform(c));case 7:case"end":return _context4.stop();}}});};exports.rnvPackage=rnvPackage;


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

(0,_common.isPlatformSupported)(c));case 3:_context5.next=5;return _regenerator.default.awrap(
(0,_common.isBuildSchemeSupported)(c));case 5:_context5.next=7;return _regenerator.default.awrap(
_rnvBuildWithPlatform(c));case 7:case"end":return _context5.stop();}}});};exports.rnvBuild=rnvBuild;


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

(0,_common.isPlatformSupported)(c));case 3:_context6.next=5;return _regenerator.default.awrap(
(0,_common.isBuildSchemeSupported)(c));case 5:_context6.next=7;return _regenerator.default.awrap(
_rnvExportWithPlatform(c));case 7:case"end":return _context6.stop();}}});};exports.rnvExport=rnvExport;


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

(0,_common.isPlatformSupported)(c));case 3:_context7.next=5;return _regenerator.default.awrap(
(0,_common.isBuildSchemeSupported)(c));case 5:_context7.next=7;return _regenerator.default.awrap(
_rnvDeployWithPlatform(c));case 7:case"end":return _context7.stop();}}});};exports.rnvDeploy=rnvDeploy;


var rnvLog=function rnvLog(c){return _regenerator.default.async(function rnvLog$(_context8){while(1){switch(_context8.prev=_context8.next){case 0:_context8.t0=
c.platform;_context8.next=_context8.t0===
_constants.ANDROID?3:_context8.t0===
_constants.ANDROID_TV?3:_context8.t0===
_constants.ANDROID_WEAR?3:_context8.t0===


_constants.IOS?6:_context8.t0===
_constants.TVOS?6:9;break;case 3:_context8.next=5;return _regenerator.default.awrap((0,_android.runAndroidLog)(c));case 5:return _context8.abrupt("return");case 6:_context8.next=8;return _regenerator.default.awrap(
(0,_apple.runAppleLog)(c));case 8:return _context8.abrupt("return");case 9:



(0,_common.logErrorPlatform)(c,c.platform);case 10:case"end":return _context8.stop();}}});};exports.rnvLog=rnvLog;






var _isWebHostEnabled=function _isWebHostEnabled(c,platform){var _c$program=
c.program,hosted=_c$program.hosted,debug=_c$program.debug;
if(debug)return false;
var bundleAssets=(0,_common.getConfigProp)(c,platform,'bundleAssets');
return(hosted||!bundleAssets)&&_constants.WEB_HOSTED_PLATFORMS.includes(platform);
};


var _configureHostedIfRequired=function _configureHostedIfRequired(c,platform){var _c$paths,project,rnv;return _regenerator.default.async(function _configureHostedIfRequired$(_context9){while(1){switch(_context9.prev=_context9.next){case 0:
if(_isWebHostEnabled(c,platform)){
(0,_common.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+"_"+platform,'public'));
(0,_common.writeCleanFile)(_path.default.join(rnv.dir,'supportFiles','appShell','index.html'),_path.default.join(project.dir,'platformBuilds',c.runtime.appId+"_"+platform,'public','index.html'),[
{pattern:'{{DEV_SERVER}}',override:"http://"+_ip.default.address()+":"+c.platformDefaults[platform].defaultPort}]);

}case 1:case"end":return _context9.stop();}}});};


var _startHostedServerIfRequired=function _startHostedServerIfRequired(c,platform){
if(_isWebHostEnabled(c,platform)){
return rnvStart(c);
}
};

var _rnvRunWithPlatform=function _rnvRunWithPlatform(c){var platform,port,target,hosted,throwErr,setupInstance,_setupInstance,_setupInstance2;return _regenerator.default.async(function _rnvRunWithPlatform$(_context10){while(1){switch(_context10.prev=_context10.next){case 0:
(0,_common.logTask)("_rnvRunWithPlatform:"+c.platform);
platform=c.platform;
port=c.program.port||c.platformDefaults[platform].defaultPort;
target=c.program.target||c.files.workspace.config.defaultTargets[platform];
hosted=c.program.hosted;

(0,_common.logTask)("_rnvRunWithPlatform:"+platform+":"+port+":"+target,_chalk.default.grey);

throwErr=function throwErr(err){
throw err;
};if(!(

_isWebHostEnabled(c,platform)&&hosted)){_context10.next=9;break;}return _context10.abrupt("return",
rnvStart(c));case 9:_context10.t0=



platform;_context10.next=_context10.t0===
_constants.IOS?12:_context10.t0===
_constants.TVOS?12:_context10.t0===



_constants.ANDROID?17:_context10.t0===
_constants.ANDROID_TV?17:_context10.t0===
_constants.ANDROID_WEAR?17:_context10.t0===








_constants.MACOS?26:_context10.t0===
_constants.WINDOWS?26:_context10.t0===



_constants.WEB?31:_context10.t0===



_constants.TIZEN?36:_context10.t0===
_constants.TIZEN_MOBILE?36:_context10.t0===
_constants.TIZEN_WATCH?36:_context10.t0===









_constants.WEBOS?49:_context10.t0===









_constants.KAIOS?62:_context10.t0===
_constants.FIREFOX_OS?62:_context10.t0===
_constants.FIREFOX_TV?62:69;break;case 12:_context10.next=14;return _regenerator.default.awrap((0,_common.cleanPlatformIfRequired)(c,platform));case 14:_context10.next=16;return _regenerator.default.awrap((0,_common.configureIfRequired)(c,platform));case 16:return _context10.abrupt("return",(0,_apple.runXcodeProject)(c,platform,target));case 17:if((0,_common.checkSdk)(c,platform,_common.logError)){_context10.next=21;break;}setupInstance=(0,_setupTools.default)(c);_context10.next=21;return _regenerator.default.awrap(setupInstance.askToInstallSDK('android'));case 21:_context10.next=23;return _regenerator.default.awrap((0,_common.cleanPlatformIfRequired)(c,platform));case 23:_context10.next=25;return _regenerator.default.awrap((0,_common.configureIfRequired)(c,platform));case 25:return _context10.abrupt("return",_runAndroid(c,platform,target,platform===_constants.ANDROID_WEAR));case 26:_context10.next=28;return _regenerator.default.awrap((0,_common.cleanPlatformIfRequired)(c,platform));case 28:_context10.next=30;return _regenerator.default.awrap((0,_common.configureIfRequired)(c,platform));case 30:return _context10.abrupt("return",(0,_electron.runElectron)(c,platform,port));case 31:_context10.next=33;return _regenerator.default.awrap((0,_common.cleanPlatformIfRequired)(c,platform));case 33:_context10.next=35;return _regenerator.default.awrap((0,_common.configureIfRequired)(c,platform));case 35:return _context10.abrupt("return",(0,_web.runWeb)(c,platform,port));case 36:if((0,_common.checkSdk)(c,platform,_common.logError)){_context10.next=40;break;}_setupInstance=(0,_setupTools.default)(c);_context10.next=40;return _regenerator.default.awrap(_setupInstance.askToInstallSDK('tizen'));case 40:_context10.next=42;return _regenerator.default.awrap((0,_common.cleanPlatformIfRequired)(c,platform));case 42:_context10.next=44;return _regenerator.default.awrap((0,_common.configureIfRequired)(c,platform));case 44:_context10.next=46;return _regenerator.default.awrap(_configureHostedIfRequired(c,platform));case 46:_context10.next=48;return _regenerator.default.awrap((0,_tizen.runTizen)(c,platform,target));case 48:return _context10.abrupt("return",_startHostedServerIfRequired(c,platform));case 49:if((0,_common.checkSdk)(c,platform,_common.logError)){_context10.next=53;break;}_setupInstance2=(0,_setupTools.default)(c);_context10.next=53;return _regenerator.default.awrap(_setupInstance2.askToInstallSDK('webos'));case 53:_context10.next=55;return _regenerator.default.awrap((0,_common.cleanPlatformIfRequired)(c,platform));case 55:_context10.next=57;return _regenerator.default.awrap((0,_common.configureIfRequired)(c,platform));case 57:_context10.next=59;return _regenerator.default.awrap(_configureHostedIfRequired(c,platform));case 59:_context10.next=61;return _regenerator.default.awrap((0,_webos.runWebOS)(c,platform,target));case 61:return _context10.abrupt("return",_startHostedServerIfRequired(c,platform));case 62:if(!(
platform===_constants.KAIOS&&!(0,_common.checkSdk)(c,platform,throwErr))){_context10.next=64;break;}return _context10.abrupt("return");case 64:_context10.next=66;return _regenerator.default.awrap(

(0,_common.cleanPlatformIfRequired)(c,platform));case 66:_context10.next=68;return _regenerator.default.awrap(
(0,_common.configureIfRequired)(c,platform));case 68:return _context10.abrupt("return",
(0,_firefox.runFirefoxProject)(c,platform));case 69:return _context10.abrupt("return",


(0,_common.logErrorPlatform)(c,platform));case 70:case"end":return _context10.stop();}}});};


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

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

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



_constants.ANDROID?11:_context11.t0===
_constants.ANDROID_TV?11:_context11.t0===
_constants.ANDROID_WEAR?11:19;break;case 6:_context11.next=8;return _regenerator.default.awrap((0,_common.cleanPlatformIfRequired)(c,platform));case 8:_context11.next=10;return _regenerator.default.awrap((0,_common.configureIfRequired)(c,platform));case 10:return _context11.abrupt("return",(0,_apple.packageBundleForXcode)(c,platform));case 11:
(0,_common.checkSdk)(c,platform);_context11.next=14;return _regenerator.default.awrap(
(0,_common.cleanPlatformIfRequired)(c,platform));case 14:_context11.next=16;return _regenerator.default.awrap(
(0,_common.configureIfRequired)(c,platform));case 16:_context11.next=18;return _regenerator.default.awrap(
(0,_android.configureGradleProject)(c,platform));case 18:return _context11.abrupt("return",
(0,_android.packageAndroid)(c,platform,target,platform===_constants.ANDROID_WEAR));case 19:


(0,_common.logErrorPlatform)(c,platform);case 20:case"end":return _context11.stop();}}});};


var _rnvExportWithPlatform=function _rnvExportWithPlatform(c){var platform;return _regenerator.default.async(function _rnvExportWithPlatform$(_context12){while(1){switch(_context12.prev=_context12.next){case 0:
(0,_common.logTask)("_rnvExportWithPlatform:"+c.platform);
platform=c.platform;_context12.t0=
platform;_context12.next=_context12.t0===
_constants.IOS?5:_context12.t0===
_constants.TVOS?5:_context12.t0===




_constants.MACOS?9:_context12.t0===
_constants.WINDOWS?9:18;break;case 5:if(c.program.only){_context12.next=8;break;}_context12.next=8;return _regenerator.default.awrap(_rnvBuildWithPlatform(c,platform));case 8:return _context12.abrupt("return",(0,_apple.exportXcodeProject)(c,platform));case 9:_context12.next=11;return _regenerator.default.awrap(

(0,_common.cleanPlatformIfRequired)(c,platform));case 11:_context12.next=13;return _regenerator.default.awrap(
(0,_common.configureIfRequired)(c,platform));case 13:_context12.next=15;return _regenerator.default.awrap(
(0,_electron.configureElectronProject)(c,platform));case 15:_context12.next=17;return _regenerator.default.awrap(
(0,_electron.buildElectron)(c,platform));case 17:return _context12.abrupt("return",
(0,_electron.exportElectron)(c,platform));case 18:


(0,_common.logErrorPlatform)(c,platform);case 19:case"end":return _context12.stop();}}});};


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

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




_constants.IOS?9:_context13.t0===





_constants.TIZEN?12:_context13.t0===




_constants.ANDROID?16:19;break;case 5:if(c.program.only){_context13.next=8;break;}_context13.next=8;return _regenerator.default.awrap(rnvBuild(c));case 8:return _context13.abrupt("return",(0,_web.deployWeb)(c,platform));case 9:if(c.program.only){_context13.next=11;break;}return _context13.abrupt("return",_rnvExportWithPlatform(c));case 11:return _context13.abrupt("return");case 12:if(c.program.only){_context13.next=15;break;}_context13.next=15;return _regenerator.default.awrap(rnvBuild(c));case 15:return _context13.abrupt("return");case 16:if(
c.program.only){_context13.next=18;break;}return _context13.abrupt("return",
_rnvBuildWithPlatform(c));case 18:return _context13.abrupt("return");case 19:



(0,_common.logErrorPlatform)(c,platform);case 20:case"end":return _context13.stop();}}});};



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

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






_constants.MACOS?16:_context14.t0===
_constants.WINDOWS?16:_context14.t0===





_constants.IOS?25:_context14.t0===
_constants.TVOS?25:_context14.t0===





_constants.WEB?31:_context14.t0===




_constants.KAIOS?38:_context14.t0===
_constants.FIREFOX_OS?38:_context14.t0===
_constants.FIREFOX_TV?38:_context14.t0===




_constants.TIZEN?45:_context14.t0===
_constants.TIZEN_MOBILE?45:_context14.t0===
_constants.TIZEN_WATCH?45:_context14.t0===





_constants.WEBOS?53:61;break;case 5:_context14.next=7;return _regenerator.default.awrap((0,_common.cleanPlatformIfRequired)(c,platform));case 7:_context14.next=9;return _regenerator.default.awrap((0,_common.configureIfRequired)(c,platform));case 9:_context14.next=11;return _regenerator.default.awrap((0,_android.configureGradleProject)(c,platform));case 11:_context14.next=13;return _regenerator.default.awrap((0,_android.packageAndroid)(c,platform));case 13:_context14.next=15;return _regenerator.default.awrap((0,_android.buildAndroid)(c,platform));case 15:return _context14.abrupt("return");case 16:_context14.next=18;return _regenerator.default.awrap((0,_common.cleanPlatformIfRequired)(c,platform));case 18:_context14.next=20;return _regenerator.default.awrap((0,_common.configureIfRequired)(c,platform));case 20:_context14.next=22;return _regenerator.default.awrap((0,_electron.configureElectronProject)(c,platform));case 22:_context14.next=24;return _regenerator.default.awrap((0,_electron.buildElectron)(c,platform));case 24:return _context14.abrupt("return");case 25:if(c.program.only){_context14.next=28;break;}_context14.next=28;return _regenerator.default.awrap(_rnvPackageWithPlatform(c,platform));case 28:_context14.next=30;return _regenerator.default.awrap((0,_apple.archiveXcodeProject)(c,platform));case 30:return _context14.abrupt("return");case 31:_context14.next=33;return _regenerator.default.awrap((0,_common.cleanPlatformIfRequired)(c,platform));case 33:_context14.next=35;return _regenerator.default.awrap((0,_common.configureIfRequired)(c,platform));case 35:_context14.next=37;return _regenerator.default.awrap((0,_web.buildWeb)(c,platform));case 37:return _context14.abrupt("return");case 38:_context14.next=40;return _regenerator.default.awrap((0,_common.cleanPlatformIfRequired)(c,platform));case 40:_context14.next=42;return _regenerator.default.awrap((0,_common.configureIfRequired)(c,platform));case 42:_context14.next=44;return _regenerator.default.awrap((0,_firefox.buildFirefoxProject)(c,platform));case 44:return _context14.abrupt("return");case 45:(0,_common.checkSdk)(c,platform);_context14.next=48;return _regenerator.default.awrap((0,_common.cleanPlatformIfRequired)(c,platform));case 48:_context14.next=50;return _regenerator.default.awrap((0,_common.configureIfRequired)(c,platform));case 50:_context14.next=52;return _regenerator.default.awrap((0,_tizen.buildTizenProject)(c,platform));case 52:return _context14.abrupt("return");case 53:
(0,_common.checkSdk)(c,platform);_context14.next=56;return _regenerator.default.awrap(
(0,_common.cleanPlatformIfRequired)(c,platform));case 56:_context14.next=58;return _regenerator.default.awrap(
(0,_common.configureIfRequired)(c,platform));case 58:_context14.next=60;return _regenerator.default.awrap(
(0,_webos.buildWebOSProject)(c,platform));case 60:return _context14.abrupt("return");case 61:



(0,_common.logErrorPlatform)(c,platform);case 62:case"end":return _context14.stop();}}});};



var _runAndroid=function _runAndroid(c,platform,target,forcePackage){return _regenerator.default.async(function _runAndroid$(_context15){while(1){switch(_context15.prev=_context15.next){case 0:
(0,_common.logTask)("_runAndroid:"+platform);if(!(

c.buildConfig.platforms[platform].runScheme==='Release'||forcePackage)){_context15.next=8;break;}_context15.next=4;return _regenerator.default.awrap(
(0,_android.packageAndroid)(c,platform));case 4:_context15.next=6;return _regenerator.default.awrap(
(0,_android.runAndroid)(c,platform,target));case 6:_context15.next=10;break;case 8:_context15.next=10;return _regenerator.default.awrap(

(0,_android.runAndroid)(c,platform,target));case 10:case"end":return _context15.stop();}}});};