var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.waitForBundler=exports.isBundlerRunning=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));var _axios=_interopRequireDefault(require("axios"));
var _ora=_interopRequireDefault(require("ora"));

var _config=_interopRequireDefault(require("../config"));

var isBundlerRunning=function isBundlerRunning(){var _ref,data;return _regenerator.default.async(function isBundlerRunning$(_context){while(1){switch(_context.prev=_context.next){case 0:_context.prev=0;_context.next=3;return _regenerator.default.awrap(

_axios.default.get("http://127.0.0.1:"+_config.default.currentPlatformDefaultPort));case 3:_ref=_context.sent;data=_ref.data;if(!
data.includes('React Native')){_context.next=7;break;}return _context.abrupt("return",true);case 7:return _context.abrupt("return",
false);case 10:_context.prev=10;_context.t0=_context["catch"](0);return _context.abrupt("return",

false);case 13:case"end":return _context.stop();}}},null,null,[[0,10]]);};exports.isBundlerRunning=isBundlerRunning;



var waitForBundler=function waitForBundler(){var attempts,maxAttempts,CHECK_INTEVAL,spinner;return _regenerator.default.async(function waitForBundler$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:
attempts=0;
maxAttempts=10;
CHECK_INTEVAL=1000;
spinner=(0,_ora.default)('Waiting for emulator to boot...').start();return _context3.abrupt("return",

new Promise(function(resolve,reject){
var interval=setInterval(function _callee(){return _regenerator.default.async(function _callee$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:
isBundlerRunning().
then(function(running){
if(running){
clearInterval(interval);
spinner.succeed();
return resolve(true);
}
attempts++;
if(attempts===maxAttempts){
clearInterval(interval);
spinner.fail('Can\'t connect to bundler. Try restarting it.');
return reject('Can\'t connect to bundler. Try restarting it.');
}
}).catch(function(){
attempts++;
if(attempts>maxAttempts){
clearInterval(interval);
spinner.fail('Can\'t connect to bundler. Try restarting it.');
return reject('Can\'t connect to bundler. Try restarting it.');
}
});case 1:case"end":return _context2.stop();}}});},
CHECK_INTEVAL);
}));case 5:case"end":return _context3.stop();}}});};exports.waitForBundler=waitForBundler;