"use strict";function _typeof(obj) {"@babel/helpers - typeof";return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {return typeof obj;} : function (obj) {return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;}, _typeof(obj);}Object.defineProperty(exports, "__esModule", { value: true });exports["default"] = void 0;var _shelljs = _interopRequireDefault(require("shelljs"));
var _getInstalledPath = require("get-installed-path");
var _path = _interopRequireDefault(require("path"));
var _child_process = require("child_process");
var _inquirer = _interopRequireDefault(require("inquirer"));

var _exec = require("../systemManager/exec");




var _logger = require("../systemManager/logger");
var _fileutils = require("../systemManager/fileutils");
var _base = _interopRequireDefault(require("./base"));
var _config = _interopRequireDefault(require("./config"));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;}function _inherits(subClass, superClass) {if (typeof superClass !== "function" && superClass !== null) {throw new TypeError("Super expression must either be null or a function");}Object.defineProperty(subClass, "prototype", { value: Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }), writable: false });if (superClass) _setPrototypeOf(subClass, superClass);}function _setPrototypeOf(o, p) {_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {o.__proto__ = p;return o;};return _setPrototypeOf(o, p);}function _createSuper(Derived) {var hasNativeReflectConstruct = _isNativeReflectConstruct();return function _createSuperInternal() {var Super = _getPrototypeOf(Derived),result;if (hasNativeReflectConstruct) {var NewTarget = _getPrototypeOf(this).constructor;result = Reflect.construct(Super, arguments, NewTarget);} else {result = Super.apply(this, arguments);}return _possibleConstructorReturn(this, result);};}function _possibleConstructorReturn(self, call) {if (call && (_typeof(call) === "object" || typeof call === "function")) {return call;} else if (call !== void 0) {throw new TypeError("Derived constructors may only return object or undefined");}return _assertThisInitialized(self);}function _assertThisInitialized(self) {if (self === void 0) {throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _isNativeReflectConstruct() {if (typeof Reflect === "undefined" || !Reflect.construct) return false;if (Reflect.construct.sham) return false;if (typeof Proxy === "function") return true;try {Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));return true;} catch (e) {return false;}}function _getPrototypeOf(o) {_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {return o.__proto__ || Object.getPrototypeOf(o);};return _getPrototypeOf(o);}var

LinuxPlatformSetup = /*#__PURE__*/function (_BasePlatformSetup) {_inherits(LinuxPlatformSetup, _BasePlatformSetup);var _super = _createSuper(LinuxPlatformSetup);
  function LinuxPlatformSetup(c) {var _this;_classCallCheck(this, LinuxPlatformSetup);
    _this = _super.call(this, 'win32', c);
    _this.scoopInstalled = false;return _this;
  }_createClass(LinuxPlatformSetup, [{ key: "checkPrereqs", value:

    function checkPrereqs() {
      (0, _logger.logInfo)("Platform ".concat(this.os));
      (0, _logger.logInfo)('Checking wget is installed');
      if ((0, _exec.commandExistsSync)('wget')) {
        this.availableDownloader = 'wget';
      }

      // check if scoop is installed
      if ((0, _exec.commandExistsSync)('scoop')) {
        this.scoopInstalled = true;
      }
    } }, { key: "installSoftware", value: function () {var _installSoftware = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(

      function _callee(software) {return regeneratorRuntime.wrap(function _callee$(_context) {while (1) {switch (_context.prev = _context.next) {case 0:_context.next = 2;return (
                  _shelljs["default"].exec(
                  (0, _fileutils.replaceHomeFolder)("~/scoop/shims/scoop install ".concat(software))));case 2:_context.next = 4;return (

                  this.reloadPathEnv());case 4:return _context.abrupt("return",
                true);case 5:case "end":return _context.stop();}}}, _callee, this);}));function installSoftware(_x) {return _installSoftware.apply(this, arguments);}return installSoftware;}() }, { key: "addScoopBucket", value:


    function addScoopBucket(bucket) {
      return _shelljs["default"].exec(
      (0, _fileutils.replaceHomeFolder)("~/scoop/shims/scoop bucket add ".concat(bucket)));

    } }, { key: "reloadPathEnv", value: function () {var _reloadPathEnv = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(

      function _callee2() {return regeneratorRuntime.wrap(function _callee2$(_context2) {while (1) {switch (_context2.prev = _context2.next) {case 0:_context2.next = 2;return (
                  _shelljs["default"].exec("".concat(
                  (0, _getInstalledPath.getInstalledPathSync)('rnv'), "/scripts/resetPath.vbs")));case 2:_context2.next = 4;return (

                  _shelljs["default"].exec('%TEMP%/resetvars.bat'));case 4:return _context2.abrupt("return",
                true);case 5:case "end":return _context2.stop();}}}, _callee2);}));function reloadPathEnv() {return _reloadPathEnv.apply(this, arguments);}return reloadPathEnv;}() }, { key: "installPrereqs", value: function () {var _installPrereqs = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(


      function _callee3() {return regeneratorRuntime.wrap(function _callee3$(_context3) {while (1) {switch (_context3.prev = _context3.next) {case 0:if (
                this.scoopInstalled) {_context3.next = 6;break;}
                (0, _logger.logInfo)('Installing Scoop...');_context3.next = 4;return (
                  _shelljs["default"].exec("powershell -executionpolicy remotesigned \"& \"\"".concat(
                  (0, _getInstalledPath.getInstalledPathSync)(
                  'rnv'), "/scripts/installPackageManager.ps1\"\"\"")));case 4:_context3.next = 6;return (


                  this.reloadPathEnv());case 6:if (

                this.availableDownloader) {_context3.next = 11;break;}
                (0, _logger.logInfo)(
                "You don't have wget or curl installed. We'll install wget for you");_context3.next = 10;return (

                  this.installSoftware('wget'));case 10:
                this.availableDownloader = 'wget';case 11:if (


                (0, _exec.commandExistsSync)('unzip')) {_context3.next = 15;break;}
                (0, _logger.logInfo)(
                "You don't have unzip installed. We'll install it for you");_context3.next = 15;return (

                  this.installSoftware('unzip'));case 15:if (


                (0, _exec.commandExistsSync)('javac')) {_context3.next = 23;break;}
                (0, _logger.logInfo)(
                "You don't have java installed. We'll install it for you");_context3.next = 19;return (

                  this.installSoftware('shellcheck'));case 19:_context3.next = 21;return (
                  this.addScoopBucket('java'));case 21:_context3.next = 23;return (
                  this.installSoftware('ojdkbuild8'));case 23:return _context3.abrupt("return",


                true);case 24:case "end":return _context3.stop();}}}, _callee3, this);}));function installPrereqs() {return _installPrereqs.apply(this, arguments);}return installPrereqs;}() }, { key: "installSdksAndEmulator", value: function () {var _installSdksAndEmulator = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(


      function _callee4() {return regeneratorRuntime.wrap(function _callee4$(_context4) {while (1) {switch (_context4.prev = _context4.next) {case 0:
                (0, _logger.logDebug)('Accepting licenses');_context4.next = 3;return (
                  (0, _exec.executeAsync)(
                  {}, "".concat(
                  this.androidSdkLocation, "/tools/bin/sdkmanager.bat --licenses")));case 3:

                (0, _logger.logDebug)('Installing SDKs', this.sdksToInstall);_context4.next = 6;return (
                  (0, _exec.executeAsync)(
                  {}, "".concat(
                  this.androidSdkLocation, "/tools/bin/sdkmanager.bat ").concat(this.sdksToInstall)));case 6:case "end":return _context4.stop();}}}, _callee4, this);}));function installSdksAndEmulator() {return _installSdksAndEmulator.apply(this, arguments);}return installSdksAndEmulator;}() }, { key: "installTizenSdk", value: function () {var _installTizenSdk = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(



      function _callee5() {var downloadDir, res;return regeneratorRuntime.wrap(function _callee5$(_context5) {while (1) {switch (_context5.prev = _context5.next) {case 0:
                downloadDir = _config["default"].tizen.downloadLocation.split('/');
                downloadDir.pop();
                downloadDir = downloadDir.join('/');
                (0, _logger.logInfo)("Opening ".concat(
                downloadDir, ". Please install the SDK then continue after it finished installing."));

                (0, _child_process.exec)("start \"\" \"".concat(downloadDir, "\""));_context5.next = 7;return (

                  _inquirer["default"].prompt({
                    type: 'input',
                    name: 'sdkPath',
                    message:
                    "Where did you install the SDK? (if you haven't changed the default just press enter)",
                    "default": 'C:\\tizen-studio',
                    validate: function validate(value) {
                      if ((0, _fileutils.fsExistsSync)(value)) return true;
                      return 'Path does not exist';
                    } }));case 7:res = _context5.sent;_context5.next = 10;return (


                  _inquirer["default"].prompt({
                    type: 'confirm',
                    name: 'toolsInstalled',
                    message:
                    'Please open Package Manager and install: Tizen SDK Tools (Main SDK), TV Extensions-* (Extension SDK). Continue after you finished installing them.',
                    validate: function validate() {
                      return (
                        (0, _fileutils.fsExistsSync)(
                        _path["default"].join(res.sdkPath, 'tools/ide/bin/tizen.bat')) ||
                        'This does not look like a Tizen SDK path');

                    } }));case 10:


                this.tizenSdkPath = res.sdkPath;case 11:case "end":return _context5.stop();}}}, _callee5, this);}));function installTizenSdk() {return _installTizenSdk.apply(this, arguments);}return installTizenSdk;}() }, { key: "installWebosSdk", value: function () {var _installWebosSdk = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(


      function _callee6() {var downloadLink, res;return regeneratorRuntime.wrap(function _callee6$(_context6) {while (1) {switch (_context6.prev = _context6.next) {case 0:
                downloadLink = _config["default"].webos.downloadLink;
                (0, _logger.logInfo)("Opening ".concat(

                downloadLink, ". Please download and install the SDK then continue after it finished installing.\nMake sure you also install the CLI and Emulator components"));



                (0, _child_process.exec)("".concat(_exec.openCommand, " ").concat(downloadLink));_context6.next = 5;return (
                  _inquirer["default"].prompt({
                    type: 'input',
                    name: 'sdkPath',
                    message:
                    "Where did you install the SDK? (if you haven't changed the default just press enter)",
                    "default": 'C:\\webOS_TV_SDK',
                    validate: function validate(value) {
                      if ((0, _fileutils.fsExistsSync)(value)) return true;
                      return 'Path does not exist';
                    } }));case 5:res = _context6.sent;_context6.next = 8;return (


                  _inquirer["default"].prompt({
                    type: 'confirm',
                    name: 'toolsInstalled',
                    message: 'Are the CLI and Emulator components installed?',
                    validate: function validate() {
                      return (
                        (0, _fileutils.fsExistsSync)(
                        _path["default"].join(res.sdkPath, 'tools/ide/bin/tizen.bat')) ||
                        'This does not look like a Tizen SDK path');

                    } }));case 8:


                this.webosSdkPath = res.sdkPath;case 9:case "end":return _context6.stop();}}}, _callee6, this);}));function installWebosSdk() {return _installWebosSdk.apply(this, arguments);}return installWebosSdk;}() }]);return LinuxPlatformSetup;}(_base["default"]);var _default =



LinuxPlatformSetup;exports["default"] = _default;
//# sourceMappingURL=windows.js.map