"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports["default"] = void 0;var _shelljs = _interopRequireDefault(require("shelljs"));
var _inquirer = _interopRequireDefault(require("inquirer"));

var _exec = require("../systemManager/exec");
var _constants = require("../constants");
var _taskManager = require("../taskManager");
var _fileutils = require("../systemManager/fileutils");
var _config = _interopRequireDefault(require("./config"));
var _config2 = _interopRequireDefault(require("../configManager/config"));
var _logger = require("../systemManager/logger");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { "default": obj };}function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {try {var info = gen[key](arg);var value = info.value;} catch (error) {reject(error);return;}if (info.done) {resolve(value);} else {Promise.resolve(value).then(_next, _throw);}}function _asyncToGenerator(fn) {return function () {var self = this,args = arguments;return new Promise(function (resolve, reject) {var gen = fn.apply(self, args);function _next(value) {asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);}function _throw(err) {asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);}_next(undefined);});};}function _classCallCheck(instance, Constructor) {if (!(instance instanceof Constructor)) {throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target, props) {for (var i = 0; i < props.length; i++) {var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);}}function _createClass(Constructor, protoProps, staticProps) {if (protoProps) _defineProperties(Constructor.prototype, protoProps);if (staticProps) _defineProperties(Constructor, staticProps);Object.defineProperty(Constructor, "prototype", { writable: false });return Constructor;}var

BasePlatformSetup = /*#__PURE__*/function () {
  function BasePlatformSetup(os, c) {_classCallCheck(this, BasePlatformSetup);
    // eslint-disable-next-line no-param-reassign
    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"';
  }_createClass(BasePlatformSetup, [{ key: "checkPrereqs", value:

    function checkPrereqs() {
      (0, _logger.logInfo)("Platform ".concat(this.os));
      (0, _logger.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 () {var _installPrereqs = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(

      function _callee() {return regeneratorRuntime.wrap(function _callee$(_context) {while (1) {switch (_context.prev = _context.next) {case 0:return _context.abrupt("return",

                true);case 1:case "end":return _context.stop();}}}, _callee);}));function installPrereqs() {return _installPrereqs.apply(this, arguments);}return installPrereqs;}() }, { key: "postInstall", value: function () {var _postInstall = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(


      function _callee2(sdk) {var location;return regeneratorRuntime.wrap(function _callee2$(_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 (
                  (0, _fileutils.updateConfigFile)(
                  { androidSdk: location },
                  this.globalConfigPath));case 4:_context2.next = 6;return (

                  (0, _taskManager.executeTask)(this.c, _constants.TASK_WORKSPACE_CONFIGURE));case 6:if (!(


                sdk === 'tizen')) {_context2.next = 11;break;}_context2.next = 9;return (
                  (0, _fileutils.updateConfigFile)(
                  { tizenSdk: this.tizenSdkPath },
                  this.globalConfigPath));case 9:_context2.next = 11;return (

                  (0, _taskManager.executeTask)(this.c, _constants.TASK_WORKSPACE_CONFIGURE));case 11:if (!(


                sdk === 'webos')) {_context2.next = 16;break;}_context2.next = 14;return (
                  (0, _fileutils.updateConfigFile)(
                  { webosSdk: this.webosSdkPath },
                  this.globalConfigPath));case 14:_context2.next = 16;return (

                  (0, _taskManager.executeTask)(this.c, _constants.TASK_WORKSPACE_CONFIGURE));case 16:case "end":return _context2.stop();}}}, _callee2, this);}));function postInstall(_x) {return _postInstall.apply(this, arguments);}return postInstall;}() }, { key: "downloadSdk", value: function () {var _downloadSdk = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(



      function _callee3(sdk) {var downloader, aditionalArguments, locationArgument, command;return regeneratorRuntime.wrap(function _callee3$(_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, _logger.logDebug)("Downloading ".concat(
                sdk, " SDK to ").concat(_config["default"][sdk].downloadLocation, " using ").concat(downloader));

                // remove the file if existing first
                _context3.next = 6;return _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 ".concat(_config["default"][sdk].downloadLocation);
                }

                command = "".concat(downloader, " ").concat(aditionalArguments, " ").concat(_config["default"][sdk].sdkUrl, " ").concat(locationArgument);

                (0, _logger.logDebug)('Running', command);
                (0, _logger.logInfo)("Downloading ".concat(sdk, " SDK..."));_context3.next = 13;return (
                  _shelljs["default"].exec(command));case 13:case "end":return _context3.stop();}}}, _callee3, this);}));function downloadSdk(_x2) {return _downloadSdk.apply(this, arguments);}return downloadSdk;}() }, { key: "unzipSdk", value: function () {var _unzipSdk = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(


      function _callee4(sdk) {return regeneratorRuntime.wrap(function _callee4$(_context4) {while (1) {switch (_context4.prev = _context4.next) {case 0:
                (0, _logger.logDebug)("Unzipping from ".concat(
                _config["default"][sdk].downloadLocation, " to ").concat(_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 (
                  _shelljs["default"].exec("unzip -qq -o ".concat(
                  _config["default"][sdk].downloadLocation, " -d ").concat(_config["default"][sdk].location)));case 5:case "end":return _context4.stop();}}}, _callee4);}));function unzipSdk(_x3) {return _unzipSdk.apply(this, arguments);}return unzipSdk;}() }, { key: "installSdksAndEmulator", value: function () {var _installSdksAndEmulator = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(



      function _callee5() {return regeneratorRuntime.wrap(function _callee5$(_context5) {while (1) {switch (_context5.prev = _context5.next) {case 0:
                (0, _logger.logTask)('installSdksAndEmulator');
                (0, _logger.logDebug)('Accepting licenses');_context5.next = 4;return (
                  _shelljs["default"].exec("yes | ".concat(
                  _config["default"].android.location, "/tools/bin/sdkmanager --licenses > /dev/null")));case 4:

                (0, _logger.logDebug)('Installing SDKs', this.sdksToInstall);_context5.next = 7;return (
                  _shelljs["default"].exec("".concat(
                  _config["default"].android.location, "/tools/bin/sdkmanager ").concat(this.sdksToInstall, " > /dev/null")));case 7:

                (0, _logger.logSuccess)("SDK succefully installed at: ".concat(_config["default"].android.location));case 8:case "end":return _context5.stop();}}}, _callee5, this);}));function installSdksAndEmulator() {return _installSdksAndEmulator.apply(this, arguments);}return installSdksAndEmulator;}() }, { key: "installSdk", value: function () {var _installSdk = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(


      function _callee6(sdk, skipPrereq) {return regeneratorRuntime.wrap(function _callee6$(_context6) {while (1) {switch (_context6.prev = _context6.next) {case 0:
                (0, _logger.logTask)("installSdk:".concat(sdk));
                !skipPrereq && this.checkPrereqs();_context6.t0 =
                !skipPrereq;if (!_context6.t0) {_context6.next = 6;break;}_context6.next = 6;return this.installPrereqs();case 6:_context6.t1 =

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




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


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


                'fastlane' ? 22 : _context6.t1 ===


                'docker' ? 25 : _context6.t1 ===


                'aws' ? 28 : 31;break;case 9:_context6.next = 11;return this.downloadSdk(sdk);case 11:_context6.next = 13;return this.unzipSdk(sdk);case 13:_context6.next = 15;return this.installSdksAndEmulator();case 15:return _context6.abrupt("break", 32);case 16:_context6.next = 18;return this.installTizenSdk();case 18:return _context6.abrupt("break", 32);case 19:_context6.next = 21;return this.installWebosSdk();case 21:return _context6.abrupt("break", 32);case 22:_context6.next = 24;return this.installFastlane();case 24:return _context6.abrupt("break", 32);case 25:_context6.next = 27;return this.installDocker();case 27:return _context6.abrupt("break", 32);case 28:_context6.next = 30;return (
                  this.installAws());case 30:return _context6.abrupt("break", 32);case 31:return _context6.abrupt("break", 32);case 32:





                this.postInstall(sdk);case 33:case "end":return _context6.stop();}}}, _callee6, this);}));function installSdk(_x4, _x5) {return _installSdk.apply(this, arguments);}return installSdk;}() }, { key: "installTizenSdk", value: function () {var _installTizenSdk = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(


      function _callee7() {return regeneratorRuntime.wrap(function _callee7$(_context7) {while (1) {switch (_context7.prev = _context7.next) {case 0:
                // to be overwritten
                (0, _logger.logError)(
                'Install webos sdk not supported yet. Follow https://developer.tizen.org/development/tizen-studio/download to install it manually');return _context7.abrupt("return",

                true);case 2:case "end":return _context7.stop();}}}, _callee7);}));function installTizenSdk() {return _installTizenSdk.apply(this, arguments);}return installTizenSdk;}() }, { key: "installWebosSdk", value: function () {var _installWebosSdk = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(


      function _callee8() {return regeneratorRuntime.wrap(function _callee8$(_context8) {while (1) {switch (_context8.prev = _context8.next) {case 0:
                // to be overwritten
                (0, _logger.logError)(
                'Install webos sdk not supported yet. Follow http://webostv.developer.lge.com/sdk/installation/ to install it manually');return _context8.abrupt("return",

                true);case 2:case "end":return _context8.stop();}}}, _callee8);}));function installWebosSdk() {return _installWebosSdk.apply(this, arguments);}return installWebosSdk;}() }, { key: "installFastlane", value: function () {var _installFastlane = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(


      function _callee9() {return regeneratorRuntime.wrap(function _callee9$(_context9) {while (1) {switch (_context9.prev = _context9.next) {case 0:
                // to be overwritten
                (0, _logger.logError)(
                'Install fastlane not supported yet. Follow https://docs.fastlane.tools/getting-started/ios/setup/ to install it manually');return _context9.abrupt("return",

                true);case 2:case "end":return _context9.stop();}}}, _callee9);}));function installFastlane() {return _installFastlane.apply(this, arguments);}return installFastlane;}() }, { key: "installDocker", value: function () {var _installDocker = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(


      function _callee10() {return regeneratorRuntime.wrap(function _callee10$(_context10) {while (1) {switch (_context10.prev = _context10.next) {case 0:
                // to be overwritten
                (0, _logger.logError)('Install docker not supported yet');return _context10.abrupt("return",
                true);case 2:case "end":return _context10.stop();}}}, _callee10);}));function installDocker() {return _installDocker.apply(this, arguments);}return installDocker;}() }, { key: "installAws", value: function () {var _installAws = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(


      function _callee11() {return regeneratorRuntime.wrap(function _callee11$(_context11) {while (1) {switch (_context11.prev = _context11.next) {case 0:
                // to be overwritten
                (0, _logger.logError)('Install aws not supported yet. Follow https://docs.aws.amazon.com/cli/latest/userguide/install-macos.html to install it manually (version 1 required)');return _context11.abrupt("return",
                true);case 2:case "end":return _context11.stop();}}}, _callee11);}));function installAws() {return _installAws.apply(this, arguments);}return installAws;}() }, { key: "askToInstallSDK", value: function () {var _askToInstallSDK = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(


      function _callee12(sdk) {var sdkInstall, response;return regeneratorRuntime.wrap(function _callee12$(_context12) {while (1) {switch (_context12.prev = _context12.next) {case 0:if (

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


                // eslint-disable-next-line prefer-destructuring
                sdkInstall = response.sdkInstall;case 5:if (!(


                this.c.program.ci || sdkInstall)) {_context12.next = 10;break;}_context12.next = 8;return (
                  this.installSdk(sdk, ['fastlane', 'docker'].includes(sdk)));case 8:_context12.next = 11;break;case 10:throw (

                  new Error("You can't run the project on this platform without ".concat(
                  sdk, " sdk installed")));case 11:case "end":return _context12.stop();}}}, _callee12, this);}));function askToInstallSDK(_x6) {return _askToInstallSDK.apply(this, arguments);}return askToInstallSDK;}() }]);return BasePlatformSetup;}();var _default =





BasePlatformSetup;exports["default"] = _default;
//# sourceMappingURL=base.js.map