import _regeneratorRuntime from"@babel/runtime/regenerator";import _slicedToArray from"@babel/runtime/helpers/slicedToArray";import got from'got';import{writeFileSync,unlink}from'fs';import open from'open';import path from'path';import ora from'ora';import inquirer from'inquirer';import{sourceMapQuery,bundleQuery}from'./packager-url';import isExpoRunning from'./is-expo-running';import isRnRunning from'./is-rn-running';var sourceMapExplorer=require('source-map-explorer');var choices=['React Native project running on port 8081','Expo project running on port 19001'];var start=function start(){var _ref,_ref2,expoRunning,rnRunning,port,prompt,_ref3,project,startTime,spinner,bundle,sourceMap,analysis,endTime;return _regeneratorRuntime.async(function start$(_context){while(1){switch(_context.prev=_context.next){case 0:console.log(' ');_context.next=3;return _regeneratorRuntime.awrap(Promise.all([isExpoRunning(),isRnRunning()]));case 3:_ref=_context.sent;_ref2=_slicedToArray(_ref,2);expoRunning=_ref2[0];rnRunning=_ref2[1];port=expoRunning?19001:8081;if(!(expoRunning&&rnRunning)){_context.next=15;break;}prompt=inquirer.createPromptModule();_context.next=12;return _regeneratorRuntime.awrap(prompt([{type:'list',name:'project',message:'Found both a React Native and an Expo project. Which one would you like to analyze?',choices:choices}]));case 12:_ref3=_context.sent;project=_ref3.project;port=project===choices[0]?8081:19001;case 15:if(!expoRunning&&!rnRunning){console.log("Could not find a React Native or Expo project running on port "+8081+" or "+19001+". Start one and run 'npx visualize-bundle' again.");process.exit(1);}startTime=Date.now();spinner=ora();spinner.start();spinner.text="Getting bundle from port "+port+"...";_context.next=22;return _regeneratorRuntime.awrap(new Promise(function(resolve){return setTimeout(resolve,100);}));case 22:_context.prev=22;_context.next=25;return _regeneratorRuntime.awrap(got((port===19001?'http://localhost:19001/node_modules/expo/AppEntry.bundle':'http://localhost:8081/index.ios.bundle')+"?"+bundleQuery));case 25:bundle=_context.sent;spinner.text="Getting map from port "+port+"...";_context.next=29;return _regeneratorRuntime.awrap(new Promise(function(resolve){return setTimeout(resolve,100);}));case 29:_context.next=31;return _regeneratorRuntime.awrap(got((port===19001?'http://localhost:19001/node_modules/expo/AppEntry.map':'http://localhost:8081/index.ios.map')+"?"+sourceMapQuery));case 31:sourceMap=_context.sent;writeFileSync(path.join(__dirname,'..','bundle.js'),bundle.body);writeFileSync(path.join(__dirname,'..','bundle.js.map'),sourceMap.body);spinner.text='Analysing bundle using source-map-explorer...';analysis=sourceMapExplorer(path.join(__dirname,'..','bundle.js'),path.join(__dirname,'..','bundle.js.map'),{html:true});writeFileSync(path.join(__dirname,'..','report.html'),analysis.html);spinner.stop();endTime=Date.now();_context.next=41;return _regeneratorRuntime.awrap(open(path.join(__dirname,'..','report.html')));case 41:console.log(' ');console.log("\u2747\uFE0F  Report generated in "+Math.floor((endTime-startTime)/1000)+"s and opened in browser.");console.log(' ');unlink(path.join(__dirname,'..','bundle.js'),function(){unlink(path.join(__dirname,'..','bundle.js.map'),function(){process.exit(0);});});_context.next=53;break;case 47:_context.prev=47;_context.t0=_context["catch"](22);console.log('Could not do bundle analysis: '+_context.t0.message);console.log(_context.t0.stack);spinner.stop();process.exit(1);case 53:case"end":return _context.stop();}}},null,null,[[22,47]]);};start();
//# sourceMappingURL=index.js.map