"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.updateRenativeConfigs = exports.configureRuntimeDefaults = void 0;var _constants = require("../constants");
var _engineManager = require("../engineManager");
var _utils = require("../systemManager/utils");
var _fileutils = require("../systemManager/fileutils");


var _common = require("../common");
var _logger = require("../systemManager/logger");


var _pluginManager = require("../pluginManager");
var _index = require("../configManager/index");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);});};}


var updateRenativeConfigs = /*#__PURE__*/function () {var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(c) {return regeneratorRuntime.wrap(function _callee$(_context) {while (1) {switch (_context.prev = _context.next) {case 0:_context.next = 2;return (
              (0, _pluginManager.loadPluginTemplates)(c));case 2:_context.next = 4;return (
              (0, _index.parseRenativeConfigs)(c));case 4:return _context.abrupt("return",
            true);case 5:case "end":return _context.stop();}}}, _callee);}));return function updateRenativeConfigs(_x) {return _ref.apply(this, arguments);};}();exports.updateRenativeConfigs = updateRenativeConfigs;


var configureRuntimeDefaults = /*#__PURE__*/function () {var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(c) {var _c$files$project, _c$files$project$conf, _c$files$project$conf2, _c$runtime$enginesByP, _c$runtime$currentEng, _c$runtime$currentEng2, _c$buildConfig, _c$buildConfig$defaul, _c$buildConfig$defaul2, _c$runtime$currentPla;var _c$buildConfig2, _c$buildConfig2$defau, _c$runtime$currentPla2, _c$buildConfig$defaul3, hosted;return regeneratorRuntime.wrap(function _callee2$(_context2) {while (1) {switch (_context2.prev = _context2.next) {case 0:
            c.runtime.appId = ((_c$files$project = c.files.project) === null || _c$files$project === void 0 ? void 0 : (_c$files$project$conf = _c$files$project.configLocal) === null || _c$files$project$conf === void 0 ? void 0 : (_c$files$project$conf2 = _c$files$project$conf._meta) === null || _c$files$project$conf2 === void 0 ? void 0 : _c$files$project$conf2.currentAppConfigId) || null;
            // c.runtime.appConfigDir = c.files.project?.configLocal?._meta?.currentAppConfigDir || null;

            (0, _logger.logTask)('configureRuntimeDefaults', "appId:".concat(c.runtime.appId));

            // TODO:
            // version
            // title
            c.runtime.currentEngine = (_c$runtime$enginesByP = c.runtime.enginesByPlatform) === null || _c$runtime$enginesByP === void 0 ? void 0 : _c$runtime$enginesByP[c.platform];
            c.runtime.currentPlatform = (_c$runtime$currentEng = c.runtime.currentEngine) === null || _c$runtime$currentEng === void 0 ? void 0 : (_c$runtime$currentEng2 = _c$runtime$currentEng.platforms) === null || _c$runtime$currentEng2 === void 0 ? void 0 : _c$runtime$currentEng2[c.platform];

            c.runtime.port = c.program.port || ((_c$buildConfig =
            c.buildConfig) === null || _c$buildConfig === void 0 ? void 0 : (_c$buildConfig$defaul = _c$buildConfig.defaults) === null || _c$buildConfig$defaul === void 0 ? void 0 : (_c$buildConfig$defaul2 = _c$buildConfig$defaul.ports) === null || _c$buildConfig$defaul2 === void 0 ? void 0 : _c$buildConfig$defaul2[c.platform]) || ((_c$runtime$currentPla =
            c.runtime.currentPlatform) === null || _c$runtime$currentPla === void 0 ? void 0 : _c$runtime$currentPla.defaultPort); //  PLATFORMS[c.platform]?.defaultPort;
            if (c.program.target !== true) {
              c.runtime.target = c.program.target || ((_c$buildConfig2 =
              c.buildConfig) === null || _c$buildConfig2 === void 0 ? void 0 : (_c$buildConfig2$defau = _c$buildConfig2.defaultTargets) === null || _c$buildConfig2$defau === void 0 ? void 0 : _c$buildConfig2$defau[c.platform]);
            } else c.runtime.target = c.program.target;
            c.runtime.scheme = c.program.scheme || 'debug';
            c.runtime.localhost = _utils.isSystemWin ? '127.0.0.1' : '0.0.0.0';
            c.runtime.timestamp = c.runtime.timestamp || Date.now();
            c.configPropsInjects = c.configPropsInjects || [];
            c.systemPropsInjects = c.systemPropsInjects || [];
            c.runtimePropsInjects = [];

            _constants.INJECTABLE_RUNTIME_PROPS.forEach(function (key) {
              c.runtimePropsInjects.push({
                pattern: "{{runtimeProps.".concat(key, "}}"),
                override: c.runtime[key] });

            });
            if (c.buildConfig) {
              c.runtime.bundleAssets = (0, _common.getConfigProp)(c, c.platform, 'bundleAssets', false);
              hosted = c.program.hosted;
              c.runtime.hosted = (hosted || !c.runtime.scheme.bundleAssets) && ((_c$runtime$currentPla2 = c.runtime.currentPlatform) === null || _c$runtime$currentPla2 === void 0 ? void 0 : _c$runtime$currentPla2.isWebHosted);

              // c.runtime.devServer = `http://${ip.address()}:${c.runtime.port}`;
              if ((_c$buildConfig$defaul3 = c.buildConfig.defaults) !== null && _c$buildConfig$defaul3 !== void 0 && _c$buildConfig$defaul3.supportedPlatforms) {
                c.runtime.supportedPlatforms = c.buildConfig.defaults.supportedPlatforms.map(function (platform) {
                  var engine = (0, _engineManager.getEngineRunnerByPlatform)(c, platform);
                  if (engine) {var _c$paths$project$plat, _c$buildConfig$defaul4, _c$runtime$currentPla3;
                    var dir = engine.originalTemplatePlatformsDir;

                    var isConnected = false;
                    var isValid = false;
                    var pDir = (_c$paths$project$plat = c.paths.project.platformTemplatesDirs) === null || _c$paths$project$plat === void 0 ? void 0 : _c$paths$project$plat[platform];
                    if (pDir) {var _pDir$includes;
                      isValid = true;
                      isConnected = pDir === null || pDir === void 0 ? void 0 : (_pDir$includes = pDir.includes) === null || _pDir$includes === void 0 ? void 0 : _pDir$includes.call(pDir, (0, _fileutils.getRealPath)(c, dir));
                    }
                    var port = ((_c$buildConfig$defaul4 = c.buildConfig.defaults) === null || _c$buildConfig$defaul4 === void 0 ? void 0 : _c$buildConfig$defaul4[platform]) || ((_c$runtime$currentPla3 = c.runtime.currentPlatform) === null || _c$runtime$currentPla3 === void 0 ? void 0 : _c$runtime$currentPla3.defaultPort);
                    return {
                      engine: engine,
                      platform: platform,
                      isConnected: isConnected,
                      port: port,
                      isValid: isValid };

                  }
                  return null;
                }).filter(function (v) {return v;});
              }
            }return _context2.abrupt("return",
            true);case 15:case "end":return _context2.stop();}}}, _callee2);}));return function configureRuntimeDefaults(_x2) {return _ref2.apply(this, arguments);};}();exports.configureRuntimeDefaults = configureRuntimeDefaults;
//# sourceMappingURL=index.js.map