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 _common=require("../common");

var isBundlerRunning=function isBundlerRunning(c){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:"+c.runtime.port+"/"+(0,_common.getConfigProp)(c,c.platform,'entryFile')+".js"));case 3:_ref=_context.sent;data=_ref.data;if(!
data.includes('import')){_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 poll=function poll(fn){var timeout=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10000;var interval=arguments.length>2&&arguments[2]!==undefined?arguments[2]:1000;
var endTime=Number(new Date())+timeout;

var spinner=(0,_ora.default)('Waiting for bundler to finish...').start();
var checkCondition=function checkCondition(resolve,reject){var result;return _regenerator.default.async(function checkCondition$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:_context2.prev=0;_context2.next=3;return _regenerator.default.awrap(

fn());case 3:result=_context2.sent;
if(result){
spinner.succeed();
resolve();
}else if(Number(new Date())<endTime){
setTimeout(checkCondition,interval,resolve,reject);
}else{
spinner.fail('Can\'t connect to bundler. Try restarting it.');
reject();
}_context2.next=11;break;case 7:_context2.prev=7;_context2.t0=_context2["catch"](0);

spinner.fail('Can\'t connect to bundler. Try restarting it.');
reject(_context2.t0);case 11:case"end":return _context2.stop();}}},null,null,[[0,7]]);};



return new Promise(checkCondition);
};

var waitForBundler=function waitForBundler(c){return _regenerator.default.async(function waitForBundler$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:return _context3.abrupt("return",poll(function(){return isBundlerRunning(c);}));case 1:case"end":return _context3.stop();}}});};exports.waitForBundler=waitForBundler;
//# sourceMappingURL=bundler.js.map