var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"logError",{enumerable:true,get:function get(){return _logger.logError;}});Object.defineProperty(exports,"logTask",{enumerable:true,get:function get(){return _logger.logTask;}});Object.defineProperty(exports,"logWarning",{enumerable:true,get:function get(){return _logger.logWarning;}});Object.defineProperty(exports,"logDebug",{enumerable:true,get:function get(){return _logger.logDebug;}});Object.defineProperty(exports,"logInfo",{enumerable:true,get:function get(){return _logger.logInfo;}});Object.defineProperty(exports,"logSuccess",{enumerable:true,get:function get(){return _logger.logSuccess;}});Object.defineProperty(exports,"logEnd",{enumerable:true,get:function get(){return _logger.logEnd;}});exports.default=exports.waitForWebpack=exports.waitForEmulator=exports.getBuildFilePath=exports.resolveNodeModulePath=exports.checkPortInUse=exports.cleanPlatformIfRequired=exports.getIP=exports.getBuildsFolder=exports.writeCleanFile=exports.configureIfRequired=exports.PLATFORM_RUNS=exports.isPlatformActive=exports.logErrorPlatform=exports.getAppVersionCode=exports.getAppDescription=exports.getGetJsBundleFile=exports.getEntryFile=exports.getAppLicense=exports.getAppAuthor=exports.getAppVersion=exports.getAppTitle=exports.getAppId=exports.getConfigProp=exports.CLI_PROPS=exports.getAppConfigId=exports.getAppTemplateFolder=exports.getAppSubFolder=exports.getBinaryPath=exports.getAppFolder=exports.checkSdk=exports.isSdkInstalled=exports.isBuildSchemeSupported=exports.isPlatformSupported=exports.isPlatformSupportedSync=exports.startBuilder=exports.initializeBuilder=exports.PARSE_RENATIVE_CONFIG=exports.NO_OP_COMMANDS=void 0;var _extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends"));var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));
var _chalk=_interopRequireDefault(require("chalk"));
var _fs=_interopRequireDefault(require("fs"));
var _path=_interopRequireDefault(require("path"));
var _detectPort=_interopRequireDefault(require("detect-port"));
var _ora=_interopRequireDefault(require("ora"));
var _ip=_interopRequireDefault(require("ip"));
var _axios=_interopRequireDefault(require("axios"));

var _fileutils=require("./systemTools/fileutils");
var _platformTools=require("./platformTools");
var _cli=_interopRequireDefault(require("./cli"));
var _templateTools=require("./templateTools");
var _pluginTools=require("./pluginTools");
var _logger=require("./systemTools/logger");




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





var _exec=require("./systemTools/exec");
var _configParser=require("./configTools/configParser");



var _projectParser=require("./projectTools/projectParser");
var _prompt=require("./systemTools/prompt");
var _migrator=require("./projectTools/migrator");

var NO_OP_COMMANDS=['fix','clean','tool','status','log','new','target','platform','help'];exports.NO_OP_COMMANDS=NO_OP_COMMANDS;
var PARSE_RENATIVE_CONFIG=['crypto'];exports.PARSE_RENATIVE_CONFIG=PARSE_RENATIVE_CONFIG;

var initializeBuilder=function initializeBuilder(cmd,subCmd,process,program){return new Promise(function(resolve,reject){
var c=(0,_configParser.createRnvConfig)(program,process,cmd,subCmd);

(0,_logger.configureLogger)(c,c.process,c.command,c.subCommand,program.info===true);
(0,_logger.logInitialize)();

resolve(c);
});};exports.initializeBuilder=initializeBuilder;

var startBuilder=function startBuilder(c){var _ref,command;return _regenerator.default.async(function startBuilder$(_context){while(1){switch(_context.prev=_context.next){case 0:
(0,_logger.logTask)('initializeBuilder');_context.next=3;return _regenerator.default.awrap(

(0,_migrator.checkAndMigrateProject)(c));case 3:_context.next=5;return _regenerator.default.awrap(
(0,_configParser.parseRenativeConfigs)(c));case 5:if(

c.command){_context.next=12;break;}if(
c.paths.project.configExists){_context.next=12;break;}_context.next=9;return _regenerator.default.awrap(
(0,_prompt.inquirerPrompt)({
type:'list',
default:'new',
name:'command',
message:'Pick a command',
choices:NO_OP_COMMANDS.sort(),
pageSize:15,
logMessage:'You need to tell rnv what to do. NOTE: your current directory is not ReNative project. RNV options will be limited'}));case 9:_ref=_context.sent;command=_ref.command;

c.command=command;case 12:if(!



NO_OP_COMMANDS.includes(c.command)){_context.next=16;break;}_context.next=15;return _regenerator.default.awrap(
(0,_configParser.configureRnvGlobal)(c));case 15:return _context.abrupt("return",
c);case 16:_context.next=18;return _regenerator.default.awrap(


(0,_migrator.checkAndMigrateProject)(c));case 18:_context.next=20;return _regenerator.default.awrap(
(0,_configParser.parseRenativeConfigs)(c));case 20:_context.next=22;return _regenerator.default.awrap(
(0,_configParser.checkIsRenativeProject)(c));case 22:_context.next=24;return _regenerator.default.awrap(
(0,_projectParser.checkAndCreateProjectPackage)(c));case 24:_context.next=26;return _regenerator.default.awrap(
(0,_configParser.configureRnvGlobal)(c));case 26:_context.next=28;return _regenerator.default.awrap(
(0,_templateTools.checkIfTemplateInstalled)(c));case 28:_context.next=30;return _regenerator.default.awrap(
(0,_configParser.fixRenativeConfigsSync)(c));case 30:_context.next=32;return _regenerator.default.awrap(
(0,_projectParser.configureNodeModules)(c));case 32:_context.next=34;return _regenerator.default.awrap(
(0,_templateTools.applyTemplate)(c));case 34:_context.next=36;return _regenerator.default.awrap(
(0,_pluginTools.configurePlugins)(c));case 36:_context.next=38;return _regenerator.default.awrap(
(0,_projectParser.configureNodeModules)(c));case 38:_context.next=40;return _regenerator.default.awrap(
(0,_configParser.updateConfig)(c,c.runtime.appId));case 40:_context.next=42;return _regenerator.default.awrap(
(0,_logger.logAppInfo)(c));case 42:return _context.abrupt("return",
c);case 43:case"end":return _context.stop();}}});};exports.startBuilder=startBuilder;


var isPlatformSupportedSync=function isPlatformSupportedSync(platform,resolve,reject){
if(!platform){
if(reject){
reject(
_chalk.default.red("You didn't specify platform. make sure you add \""+
_chalk.default.white.bold(
'-p <PLATFORM>')+"\" option to your command!"));



}
return false;
}
if(!_constants.SUPPORTED_PLATFORMS.includes(platform)){
if(reject)reject(_chalk.default.red("Platform "+platform+" is not supported. Use one of the following: "+_chalk.default.white(_constants.SUPPORTED_PLATFORMS.join(', '))+" ."));
return false;
}
if(resolve)resolve();
return true;
};exports.isPlatformSupportedSync=isPlatformSupportedSync;

var isPlatformSupported=function isPlatformSupported(c){var platformsAsObj,opts,_ref2,platform;return _regenerator.default.async(function isPlatformSupported$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:
(0,_logger.logTask)("isPlatformSupported:"+c.platform);
platformsAsObj=c.buildConfig?c.buildConfig.platforms:c.supportedPlatforms;
if(!platformsAsObj)platformsAsObj=_constants.SUPPORTED_PLATFORMS;
opts=(0,_prompt.generateOptions)(platformsAsObj);if(!(

!c.platform||c.platform==='?'||!_constants.SUPPORTED_PLATFORMS.includes(c.platform))){_context2.next=12;break;}_context2.next=7;return _regenerator.default.awrap(
(0,_prompt.inquirerPrompt)({
name:'platform',
type:'list',
message:'Pick one of available platforms',
choices:opts.keysAsArray,
logMessage:'You need to specify platform'}));case 7:_ref2=_context2.sent;platform=_ref2.platform;


c.platform=platform;
c.program.platform=platform;return _context2.abrupt("return",
platform);case 12:case"end":return _context2.stop();}}});};exports.isPlatformSupported=isPlatformSupported;



var isBuildSchemeSupported=function isBuildSchemeSupported(c){var scheme,buildSchemes,schemeDoesNotExist,opts,_ref3,selectedScheme;return _regenerator.default.async(function isBuildSchemeSupported$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:
(0,_logger.logTask)("isBuildSchemeSupported:"+c.platform);

scheme=c.program.scheme;

if(!c.buildConfig.platforms[c.platform]){
c.buildConfig.platforms[c.platform]={};
}

buildSchemes=c.buildConfig.platforms[c.platform].buildSchemes;if(


buildSchemes){_context3.next=7;break;}
(0,_logger.logWarning)("Your appConfig for platform "+c.platform+" has no buildSchemes. Will continue with defaults");return _context3.abrupt("return");case 7:



schemeDoesNotExist=scheme&&!buildSchemes[scheme];if(!(
scheme==='?'||schemeDoesNotExist)){_context3.next=17;break;}
if(schemeDoesNotExist&&scheme&&scheme!=='?'){
(0,_logger.logError)('Build scheme you picked does not exists.');
}
opts=(0,_prompt.generateOptions)(buildSchemes);_context3.next=13;return _regenerator.default.awrap(

(0,_prompt.inquirerPrompt)({
name:'selectedScheme',
type:'list',
message:'Pick one of available buildSchemes',
choices:opts.keysAsArray,
logMessage:'You need to specify scheme'}));case 13:_ref3=_context3.sent;selectedScheme=_ref3.selectedScheme;


c.program.scheme=selectedScheme;return _context3.abrupt("return",
selectedScheme);case 17:return _context3.abrupt("return",

scheme);case 18:case"end":return _context3.stop();}}});};exports.isBuildSchemeSupported=isBuildSchemeSupported;


var isSdkInstalled=function isSdkInstalled(c,platform){
(0,_logger.logTask)("isSdkInstalled: "+platform);

if(c.files.workspace.config){
var sdkPlatform=_constants.SDK_PLATFORMS[platform];
if(sdkPlatform)return _fs.default.existsSync((0,_fileutils.getRealPath)(c,c.files.workspace.config.sdks[sdkPlatform]));
}

return false;
};exports.isSdkInstalled=isSdkInstalled;

var checkSdk=function checkSdk(c,platform,reject){
if(!isSdkInstalled(c,platform)){var _c$files$workspace$co,_c$files$workspace$co2;
var err=platform+" requires SDK to be installed. check your "+_chalk.default.white(c.paths.workspace.config)+" file if you SDK path is correct. current value is "+_chalk.default.white((_c$files$workspace$co=c.files.workspace.config)==null?void 0:(_c$files$workspace$co2=_c$files$workspace$co.sdks)==null?void 0:_c$files$workspace$co2.ANDROID_SDK);
if(reject){
reject(err);
}else{
throw new Error(err);
}
return false;
}
return true;
};exports.checkSdk=checkSdk;

var getAppFolder=function getAppFolder(c,platform){return _path.default.join(c.paths.project.builds.dir,c.runtime.appId+"_"+platform);};exports.getAppFolder=getAppFolder;

var getBinaryPath=function getBinaryPath(c,platform){
var appFolder=getAppFolder(c,platform);
var id=getConfigProp(c,platform,'id');
var signingConfig=getConfigProp(c,platform,'signingConfig','debug');
var version=getAppVersion(c,platform);
var productName='ReNative - macos';
var appName=getConfigProp(c,platform,'appName');

switch(platform){
case _constants.IOS:
case _constants.TVOS:
return appFolder+"/release/RNVApp.ipa";
case _constants.ANDROID:
case _constants.ANDROID_TV:
case _constants.ANDROID_WEAR:
return appFolder+"/app/build/outputs/apk/"+signingConfig+"/app-"+signingConfig+".apk";
case _constants.WEB:
return appFolder+"/public";
case _constants.MACOS:
case _constants.WINDOWS:
return appFolder+"/build/release/"+productName+"-"+version;
case _constants.TIZEN:
case _constants.TIZEN_MOBILE:
return appFolder+"/output/"+appName+".wgt";
case _constants.WEBOS:
return appFolder+"/output/"+id+"_"+version+"_all.ipk";}


return appFolder;
};exports.getBinaryPath=getBinaryPath;

var getAppSubFolder=function getAppSubFolder(c,platform){
var subFolder='';
if(platform===_constants.IOS)subFolder='RNVApp';else
if(platform===_constants.TVOS)subFolder='RNVAppTVOS';
return _path.default.join(getAppFolder(c,platform),subFolder);
};exports.getAppSubFolder=getAppSubFolder;

var getAppTemplateFolder=function getAppTemplateFolder(c,platform){return _path.default.join(c.paths.project.platformTemplatesDirs[platform],""+platform);};exports.getAppTemplateFolder=getAppTemplateFolder;

var getAppConfigId=function getAppConfigId(c){return c.buildConfig.id;};exports.getAppConfigId=getAppConfigId;

var _getValueOrMergedObject=function _getValueOrMergedObject(resultCli,o1,o2,o3){
if(resultCli){
return resultCli;
}
if(o1){
if(Array.isArray(o1)||typeof o1!=='object')return o1;
var val=(0,_extends2.default)(o3||{},o2||{},o1);
return val;
}
if(o1===null)return null;
if(o2){
if(Array.isArray(o2)||typeof o2!=='object')return o2;
return(0,_extends2.default)(o3||{},o2);
}
if(o2===null)return null;
return o3;
};

var CLI_PROPS=[
'provisioningStyle',
'codeSignIdentity',
'provisionProfileSpecifier'];exports.CLI_PROPS=CLI_PROPS;


var getConfigProp=function getConfigProp(c,platform,key,defaultVal){var _c$buildConfig$common;
if(!c.buildConfig){
(0,_logger.logError)('getConfigProp: c.buildConfig is undefined!');
return null;
}
var p=c.buildConfig.platforms[platform];
var ps=_getScheme(c);
var resultPlatforms;
var scheme;
if(p){
scheme=p.buildSchemes?p.buildSchemes[ps]:null;
resultPlatforms=c.buildConfig.platforms[platform][key];
}


scheme=scheme||{};
var resultCli=CLI_PROPS.includes(key)?c.program[key]:null;
var resultScheme=scheme[key];
var resultCommon=(_c$buildConfig$common=c.buildConfig.common)==null?void 0:_c$buildConfig$common[key];

var result=_getValueOrMergedObject(resultCli,resultScheme,resultPlatforms,resultCommon);

(0,_logger.logTask)("getConfigProp:"+platform+":"+key+":"+result,_chalk.default.grey);
if(result===null||result===undefined)return defaultVal;
return result;
};exports.getConfigProp=getConfigProp;

var getAppId=function getAppId(c,platform){
var id=getConfigProp(c,platform,'id');
var idSuffix=getConfigProp(c,platform,'idSuffix');
return idSuffix?""+id+idSuffix:id;
};exports.getAppId=getAppId;

var getAppTitle=function getAppTitle(c,platform){return getConfigProp(c,platform,'title');};exports.getAppTitle=getAppTitle;

var getAppVersion=function getAppVersion(c,platform){var _c$buildConfig$platfo,_c$buildConfig$platfo2,_c$buildConfig$common2,_c$files$project$pack;return((_c$buildConfig$platfo=c.buildConfig.platforms)==null?void 0:(_c$buildConfig$platfo2=_c$buildConfig$platfo[platform])==null?void 0:_c$buildConfig$platfo2.version)||((_c$buildConfig$common2=c.buildConfig.common)==null?void 0:_c$buildConfig$common2.version)||((_c$files$project$pack=c.files.project.package)==null?void 0:_c$files$project$pack.version);};exports.getAppVersion=getAppVersion;

var getAppAuthor=function getAppAuthor(c,platform){var _c$buildConfig$platfo3,_c$buildConfig$platfo4,_c$buildConfig$common3,_c$files$project$pack2;return((_c$buildConfig$platfo3=c.buildConfig.platforms)==null?void 0:(_c$buildConfig$platfo4=_c$buildConfig$platfo3[platform])==null?void 0:_c$buildConfig$platfo4.author)||((_c$buildConfig$common3=c.buildConfig.common)==null?void 0:_c$buildConfig$common3.author)||((_c$files$project$pack2=c.files.project.package)==null?void 0:_c$files$project$pack2.author);};exports.getAppAuthor=getAppAuthor;

var getAppLicense=function getAppLicense(c,platform){var _c$buildConfig$platfo5,_c$buildConfig$platfo6,_c$buildConfig$common4,_c$files$project$pack3;return((_c$buildConfig$platfo5=c.buildConfig.platforms)==null?void 0:(_c$buildConfig$platfo6=_c$buildConfig$platfo5[platform])==null?void 0:_c$buildConfig$platfo6.license)||((_c$buildConfig$common4=c.buildConfig.common)==null?void 0:_c$buildConfig$common4.license)||((_c$files$project$pack3=c.files.project.package)==null?void 0:_c$files$project$pack3.license);};exports.getAppLicense=getAppLicense;

var getEntryFile=function getEntryFile(c,platform){var _c$buildConfig$platfo7,_c$buildConfig$platfo8;return(_c$buildConfig$platfo7=c.buildConfig.platforms)==null?void 0:(_c$buildConfig$platfo8=_c$buildConfig$platfo7[platform])==null?void 0:_c$buildConfig$platfo8.entryFile;};exports.getEntryFile=getEntryFile;

var getGetJsBundleFile=function getGetJsBundleFile(c,platform){return getConfigProp(c,platform,'getJsBundleFile');};exports.getGetJsBundleFile=getGetJsBundleFile;

var getAppDescription=function getAppDescription(c,platform){var _c$buildConfig$platfo9,_c$buildConfig$platfo10,_c$buildConfig$common5,_c$files$project$pack4;return((_c$buildConfig$platfo9=c.buildConfig.platforms)==null?void 0:(_c$buildConfig$platfo10=_c$buildConfig$platfo9[platform])==null?void 0:_c$buildConfig$platfo10.description)||((_c$buildConfig$common5=c.buildConfig.common)==null?void 0:_c$buildConfig$common5.description)||((_c$files$project$pack4=c.files.project.package)==null?void 0:_c$files$project$pack4.description);};exports.getAppDescription=getAppDescription;

var getAppVersionCode=function getAppVersionCode(c,platform){var _c$buildConfig$platfo11,_c$buildConfig$platfo12;
if((_c$buildConfig$platfo11=c.buildConfig.platforms)==null?void 0:(_c$buildConfig$platfo12=_c$buildConfig$platfo11[platform])==null?void 0:_c$buildConfig$platfo12.versionCode){
return c.buildConfig.platforms[platform].versionCode;
}
if(c.buildConfig.common.versionCode){
return c.buildConfig.common.versionCode;
}
var version=getAppVersion(c,platform);

var vc='';
version.
split('-')[0].
split('.').
forEach(function(v){
vc+=v.length>1?v:"0"+v;
});
return Number(vc).toString();
};exports.getAppVersionCode=getAppVersionCode;

var logErrorPlatform=function logErrorPlatform(c,platform){
(0,_logger.logError)("Platform: "+_chalk.default.white(platform)+" doesn't support command: "+_chalk.default.white(c.command));
};exports.logErrorPlatform=logErrorPlatform;

var isPlatformActive=function isPlatformActive(c,platform,resolve){
if(!c.buildConfig||!c.buildConfig.platforms){
(0,_logger.logError)("Looks like your appConfigFile is not configured properly! check "+_chalk.default.white(c.paths.appConfig.config)+" location.");
if(resolve)resolve();
return false;
}
if(!c.buildConfig.platforms[platform]){
console.log("Platform "+platform+" not configured for "+c.runtime.appId+". skipping.");
if(resolve)resolve();
return false;
}
return true;
};exports.isPlatformActive=isPlatformActive;

var PLATFORM_RUNS={};exports.PLATFORM_RUNS=PLATFORM_RUNS;

var configureIfRequired=function configureIfRequired(c,platform){return new Promise(function(resolve,reject){
(0,_logger.logTask)("configureIfRequired:"+platform);

if(PLATFORM_RUNS[platform]){
resolve();
return;
}
PLATFORM_RUNS[platform]=true;var
device=c.program.device;
var nc={
command:'configure',
program:{
appConfig:c.id,
update:false,
platform:platform,
device:device}};



if(c.program.reset){
(0,_platformTools.cleanPlatformBuild)(c,platform).
then(function(){return(0,_projectParser.cleanPlaformAssets)(c);}).
then(function(){return(0,_platformTools.createPlatformBuild)(c,platform);}).
then(function(){return(0,_cli.default)(c,nc);}).
then(function(){return resolve(c);}).
catch(function(e){return reject(e);});
}else{
(0,_platformTools.createPlatformBuild)(c,platform).
then(function(){return(0,_cli.default)(c,nc);}).
then(function(){return resolve(c);}).
catch(function(e){return reject(e);});
}
});};exports.configureIfRequired=configureIfRequired;

var writeCleanFile=function writeCleanFile(source,destination,overrides){

if(!_fs.default.existsSync(source)){
(0,_logger.logError)("Cannot write file. source path doesn't exists: "+source);
return;
}
if(!_fs.default.existsSync(destination)){
(0,_logger.logWarning)("destination path doesn't exists: "+destination+". will create new one");

}
var pFile=_fs.default.readFileSync(source,'utf8');
var pFileClean=pFile;
overrides.forEach(function(v){
var regEx=new RegExp(v.pattern,'g');
pFileClean=pFileClean.replace(regEx,v.override);
});

_fs.default.writeFileSync(destination,pFileClean,'utf8');
};exports.writeCleanFile=writeCleanFile;

var _getScheme=function _getScheme(c){return c.program.scheme||'debug';};

var getBuildsFolder=function getBuildsFolder(c,platform,customPath){
var pp=customPath||c.paths.appConfig.dir;



var p=_path.default.join(pp,"builds/"+platform+"@"+_getScheme(c));
if(_fs.default.existsSync(p))return p;
return _path.default.join(pp,"builds/"+platform);
};exports.getBuildsFolder=getBuildsFolder;

var getIP=function getIP(){return _ip.default.address();};exports.getIP=getIP;

var cleanPlatformIfRequired=function cleanPlatformIfRequired(c,platform){return new Promise(function(resolve,reject){
if(c.program.reset){
(0,_logger.logInfo)("You passed "+_chalk.default.white('-r')+" argument. paltform "+_chalk.default.white(platform)+" will be cleaned up first!");
(0,_platformTools.cleanPlatformBuild)(c,platform).
then(function(){return resolve(c);}).
catch(function(e){return reject(e);});
}else{
resolve();
}
});};exports.cleanPlatformIfRequired=cleanPlatformIfRequired;

var checkPortInUse=function checkPortInUse(c,platform,port){return new Promise(function(resolve,reject){
(0,_detectPort.default)(port,function(err,availablePort){
if(err){
reject(err);
return;
}
resolve(port!==availablePort);
});
});};exports.checkPortInUse=checkPortInUse;

var resolveNodeModulePath=function resolveNodeModulePath(c,filePath){
var pth=_path.default.join(c.paths.rnv.nodeModulesDir,filePath);
if(!_fs.default.existsSync(pth)){
pth=_path.default.join(c.paths.project.nodeModulesDir,filePath);
}
return pth;
};exports.resolveNodeModulePath=resolveNodeModulePath;

var getBuildFilePath=function getBuildFilePath(c,platform,filePath){

var sp=_path.default.join(getAppTemplateFolder(c,platform),filePath);

var sp2=_path.default.join(getBuildsFolder(c,platform,c.paths.project.projectConfig.dir),filePath);
if(_fs.default.existsSync(sp2))sp=sp2;

var sp3=_path.default.join(getBuildsFolder(c,platform),filePath);
if(_fs.default.existsSync(sp3))sp=sp3;
return sp;
};exports.getBuildFilePath=getBuildFilePath;

var waitForEmulator=function waitForEmulator(c,cli,command,callback){var attempts,maxAttempts,CHECK_INTEVAL,maxErrorLength,spinner;return _regenerator.default.async(function waitForEmulator$(_context4){while(1){switch(_context4.prev=_context4.next){case 0:
attempts=0;
maxAttempts=10;
CHECK_INTEVAL=2000;
maxErrorLength=c.program.maxErrorLength;
spinner=(0,_ora.default)('Waiting for emulator to boot...').start();return _context4.abrupt("return",

new Promise(function(resolve,reject){
var interval=setInterval(function(){
(0,_exec.execCLI)(c,cli,command,{silent:true,timeout:10000,maxErrorLength:maxErrorLength}).
then(function(resp){
if(callback(resp)){
clearInterval(interval);
spinner.succeed();
return resolve(true);
}
attempts++;
if(attempts===maxAttempts){
clearInterval(interval);
spinner.fail('Can\'t connect to the running emulator. Try restarting it.');
return reject('Can\'t connect to the running emulator. Try restarting it.');
}
}).catch(function(){
attempts++;
if(attempts>maxAttempts){
clearInterval(interval);
spinner.fail('Can\'t connect to the running emulator. Try restarting it.');
return reject('Can\'t connect to the running emulator. Try restarting it.');
}
});
},CHECK_INTEVAL);
}));case 6:case"end":return _context4.stop();}}});};exports.waitForEmulator=waitForEmulator;


var waitForWebpack=function waitForWebpack(c,port){
(0,_logger.logTask)("waitForWebpack:"+port);
var attempts=0;
var maxAttempts=10;
var CHECK_INTEVAL=2000;
var spinner=(0,_ora.default)('Waiting for webpack to finish...').start();

var extendConfig=getConfigProp(c,c.platform,'webpackConfig',{});
var devServerHost=extendConfig.devServerHost||'0.0.0.0';
if(_fileutils.isRunningOnWindows&&devServerHost==='0.0.0.0'){
devServerHost='127.0.0.1';
}

return new Promise(function(resolve,reject){
var interval=setInterval(function(){
_axios.default.get("http://"+devServerHost+":"+port).then(function(res){
if(res.status===200){
var isReady=res.data.toString().includes('<!DOCTYPE html>');
if(isReady){
clearInterval(interval);
spinner.succeed();
return resolve(true);
}
}
attempts++;
if(attempts===maxAttempts){
clearInterval(interval);
spinner.fail('Can\'t connect to webpack. Try restarting it.');
return reject('Can\'t connect to webpack. Try restarting it.');
}
}).catch(function(){
attempts++;
if(attempts>maxAttempts){
clearInterval(interval);
spinner.fail('Can\'t connect to webpack. Try restarting it.');
return reject('Can\'t connect to webpack. Try restarting it.');
}
});
},CHECK_INTEVAL);
});
};exports.waitForWebpack=waitForWebpack;var _default=












{
getBuildFilePath:getBuildFilePath,
getBuildsFolder:getBuildsFolder,
logWelcome:_logger.logWelcome,
isPlatformSupported:isPlatformSupported,
isBuildSchemeSupported:isBuildSchemeSupported,
isPlatformSupportedSync:isPlatformSupportedSync,
getAppFolder:getAppFolder,
getAppTemplateFolder:getAppTemplateFolder,
logTask:_logger.logTask,
logComplete:_logger.logComplete,
logError:_logger.logError,
initializeBuilder:initializeBuilder,
startBuilder:startBuilder,
logDebug:_logger.logDebug,
logInfo:_logger.logInfo,
logErrorPlatform:logErrorPlatform,
isPlatformActive:isPlatformActive,
isSdkInstalled:isSdkInstalled,
checkSdk:checkSdk,
logEnd:_logger.logEnd,
logWarning:_logger.logWarning,
configureIfRequired:configureIfRequired,
getAppId:getAppId,
getAppTitle:getAppTitle,
getAppVersion:getAppVersion,
getAppVersionCode:getAppVersionCode,
writeCleanFile:writeCleanFile,
getEntryFile:getEntryFile,
getGetJsBundleFile:getGetJsBundleFile,
getAppConfigId:getAppConfigId,
getAppDescription:getAppDescription,
getAppAuthor:getAppAuthor,
getAppLicense:getAppLicense,
logSuccess:_logger.logSuccess,
getConfigProp:getConfigProp,
getIP:getIP,
cleanPlatformIfRequired:cleanPlatformIfRequired,
checkPortInUse:checkPortInUse,
resolveNodeModulePath:resolveNodeModulePath,
configureRnvGlobal:_configParser.configureRnvGlobal,
waitForEmulator:waitForEmulator};exports.default=_default;