var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));var _createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _shelljs=_interopRequireDefault(require("shelljs"));
var _inquirer=_interopRequireDefault(require("inquirer"));

var _exec=require("../systemTools/exec");
var _common=require("../common");
var _configParser=require("../configTools/configParser");
var _fileutils=require("../systemTools/fileutils");
var _config=_interopRequireDefault(require("./config"));
var _config2=_interopRequireDefault(require("../config"));var

BasePlatformSetup=function(){
function BasePlatformSetup(os,c){(0,_classCallCheck2.default)(this,BasePlatformSetup);

if(!c)c=_config2.default.getConfig();var _c=
c,paths=_c.paths;
this.os=os;
this.c=c;
this.globalConfigPath=paths.workspace.config;
this.availableDownloader=null;
this.androidSdkLocation=(0,_fileutils.replaceHomeFolder)('~/Android');
this.sdksToInstall='"build-tools;28.0.3" "emulator" "extras;android;m2repository" "extras;google;m2repository" "patcher;v4" "platform-tools" "platforms;android-28" "sources;android-28" "system-images;android-28;google_apis_playstore;x86" "tools"';
}(0,_createClass2.default)(BasePlatformSetup,[{key:"checkPrereqs",value:function checkPrereqs()

{
(0,_common.logInfo)("Platform "+this.os);
(0,_common.logInfo)('Checking if wget or curl is installed');
if((0,_exec.commandExistsSync)('wget')){
this.availableDownloader='wget';
}else if((0,_exec.commandExistsSync)('curl')){
this.availableDownloader='curl';
}
}},{key:"installPrereqs",value:function installPrereqs(){return _regenerator.default.async(function installPrereqs$(_context){while(1){switch(_context.prev=_context.next){case 0:return _context.abrupt("return",



true);case 1:case"end":return _context.stop();}}});}},{key:"postInstall",value:function postInstall(


sdk){var location;return _regenerator.default.async(function postInstall$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:if(!(
sdk==='android')){_context2.next=6;break;}
location=_config.default.android.location;_context2.next=4;return _regenerator.default.awrap(
(0,_fileutils.updateConfigFile)({androidSdk:location},this.globalConfigPath));case 4:_context2.next=6;return _regenerator.default.awrap(
(0,_configParser.configureRnvGlobal)(this.c));case 6:if(!(


sdk==='tizen')){_context2.next=11;break;}_context2.next=9;return _regenerator.default.awrap(
(0,_fileutils.updateConfigFile)({tizenSdk:this.tizenSdkPath},this.globalConfigPath));case 9:_context2.next=11;return _regenerator.default.awrap(
(0,_configParser.configureRnvGlobal)(this.c));case 11:if(!(


sdk==='webos')){_context2.next=16;break;}_context2.next=14;return _regenerator.default.awrap(
(0,_fileutils.updateConfigFile)({webosSdk:this.webosSdkPath},this.globalConfigPath));case 14:_context2.next=16;return _regenerator.default.awrap(
(0,_configParser.configureRnvGlobal)(this.c));case 16:case"end":return _context2.stop();}}},null,this);}},{key:"downloadSdk",value:function downloadSdk(



sdk){var downloader,aditionalArguments,locationArgument,command;return _regenerator.default.async(function downloadSdk$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:
downloader=this.availableDownloader;if(
downloader){_context3.next=3;break;}throw new Error('Wget or cURL not installed!');case 3:
(0,_common.logDebug)("Downloading "+sdk+" SDK to "+_config.default[sdk].downloadLocation+" using "+downloader);_context3.next=6;return _regenerator.default.awrap(

_shelljs.default.rm(_config.default[sdk].downloadLocation));case 6:



if(downloader==='wget'){
aditionalArguments='-q';
locationArgument=(0,_fileutils.replaceHomeFolder)('-P ~/');
}
if(downloader==='curl'){
aditionalArguments='-#';
locationArgument="--output "+_config.default[sdk].downloadLocation;
}

command=downloader+" "+aditionalArguments+" "+_config.default[sdk].sdkUrl+" "+locationArgument;

(0,_common.logDebug)('Running',command);
(0,_common.logInfo)("Downloading "+sdk+" SDK...");_context3.next=13;return _regenerator.default.awrap(
_shelljs.default.exec(command));case 13:case"end":return _context3.stop();}}},null,this);}},{key:"unzipSdk",value:function unzipSdk(


sdk){return _regenerator.default.async(function unzipSdk$(_context4){while(1){switch(_context4.prev=_context4.next){case 0:
(0,_common.logDebug)("Unzipping from "+_config.default[sdk].downloadLocation+" to "+_config.default[sdk].location);if(
(0,_exec.commandExistsSync)('unzip')){_context4.next=3;break;}throw new Error('unzip is not installed');case 3:_context4.next=5;return _regenerator.default.awrap(
_shelljs.default.exec("unzip -qq -o "+_config.default[sdk].downloadLocation+" -d "+_config.default[sdk].location));case 5:case"end":return _context4.stop();}}});}},{key:"installSdksAndEmulator",value:function installSdksAndEmulator(){return _regenerator.default.async(function installSdksAndEmulator$(_context5){while(1){switch(_context5.prev=_context5.next){case 0:



(0,_common.logDebug)('Accepting licenses');_context5.next=3;return _regenerator.default.awrap(
_shelljs.default.exec("yes | "+_config.default.android.location+"/tools/bin/sdkmanager --licenses > /dev/null"));case 3:
(0,_common.logDebug)('Installing SDKs',this.sdksToInstall);_context5.next=6;return _regenerator.default.awrap(
_shelljs.default.exec(_config.default.android.location+"/tools/bin/sdkmanager "+this.sdksToInstall+" > /dev/null"));case 6:case"end":return _context5.stop();}}},null,this);}},{key:"installSdk",value:function installSdk(


sdk,skipPrereq){return _regenerator.default.async(function installSdk$(_context6){while(1){switch(_context6.prev=_context6.next){case 0:
!skipPrereq&&this.checkPrereqs();_context6.t0=
!skipPrereq;if(!_context6.t0){_context6.next=5;break;}_context6.next=5;return _regenerator.default.awrap(this.installPrereqs());case 5:_context6.t1=

sdk;_context6.next=_context6.t1===
'android'?8:_context6.t1===




'tizen'?15:_context6.t1===


'webos'?18:_context6.t1===


'fastlane'?21:24;break;case 8:_context6.next=10;return _regenerator.default.awrap(this.downloadSdk(sdk));case 10:_context6.next=12;return _regenerator.default.awrap(this.unzipSdk(sdk));case 12:_context6.next=14;return _regenerator.default.awrap(this.installSdksAndEmulator());case 14:return _context6.abrupt("break",25);case 15:_context6.next=17;return _regenerator.default.awrap(this.installTizenSdk());case 17:return _context6.abrupt("break",25);case 18:_context6.next=20;return _regenerator.default.awrap(this.installWebosSdk());case 20:return _context6.abrupt("break",25);case 21:_context6.next=23;return _regenerator.default.awrap(
this.installFastlane());case 23:return _context6.abrupt("break",25);case 24:return _context6.abrupt("break",25);case 25:





this.postInstall(sdk);case 26:case"end":return _context6.stop();}}},null,this);}},{key:"installTizenSdk",value:function installTizenSdk(){return _regenerator.default.async(function installTizenSdk$(_context7){while(1){switch(_context7.prev=_context7.next){case 0:return _context7.abrupt("return",




true);case 1:case"end":return _context7.stop();}}});}},{key:"installWebosSdk",value:function installWebosSdk(){return _regenerator.default.async(function installWebosSdk$(_context8){while(1){switch(_context8.prev=_context8.next){case 0:return _context8.abrupt("return",




true);case 1:case"end":return _context8.stop();}}});}},{key:"installFastlane",value:function installFastlane(){return _regenerator.default.async(function installFastlane$(_context9){while(1){switch(_context9.prev=_context9.next){case 0:return _context9.abrupt("return",




true);case 1:case"end":return _context9.stop();}}});}},{key:"askToInstallSDK",value:function askToInstallSDK(


sdk){var sdkInstall,response;return _regenerator.default.async(function askToInstallSDK$(_context10){while(1){switch(_context10.prev=_context10.next){case 0:if(

this.c.program.ci){_context10.next=5;break;}_context10.next=3;return _regenerator.default.awrap(
_inquirer.default.prompt([{
name:'sdkInstall',
type:'confirm',
message:"Do you want to install "+sdk+" SDK?"}]));case 3:response=_context10.sent;


sdkInstall=response.sdkInstall;case 5:if(!(


this.c.program.ci||sdkInstall)){_context10.next=8;break;}_context10.next=8;return _regenerator.default.awrap(
this.installSdk(sdk,sdk==='fastlane'));case 8:case"end":return _context10.stop();}}},null,this);}}]);return BasePlatformSetup;}();var _default=




BasePlatformSetup;exports.default=_default;