var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.configureRuntimeDefaults=exports.updateRenativeConfigs=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));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("./index");


var updateRenativeConfigs=function updateRenativeConfigs(c){return _regenerator.default.async(function updateRenativeConfigs$(_context){while(1){switch(_context.prev=_context.next){case 0:_context.next=2;return _regenerator.default.awrap(
(0,_pluginManager.loadPluginTemplates)(c));case 2:_context.next=4;return _regenerator.default.awrap(
(0,_index.parseRenativeConfigs)(c));case 4:return _context.abrupt("return",
true);case 5:case"end":return _context.stop();}}},null,null,null,Promise);};exports.updateRenativeConfigs=updateRenativeConfigs;


var configureRuntimeDefaults=function configureRuntimeDefaults(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$files$workspace$co,_c$files$workspace$co2,_c$runtime$currentPla2,_c$buildConfig$defaul3,hosted;return _regenerator.default.async(function configureRuntimeDefaults$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:
c.runtime.appId=((_c$files$project=c.files.project)==null?void 0:(_c$files$project$conf=_c$files$project.configLocal)==null?void 0:(_c$files$project$conf2=_c$files$project$conf._meta)==null?void 0:_c$files$project$conf2.currentAppConfigId)||null;


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




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

c.runtime.port=c.program.port||((_c$buildConfig=
c.buildConfig)==null?void 0:(_c$buildConfig$defaul=_c$buildConfig.defaults)==null?void 0:(_c$buildConfig$defaul2=_c$buildConfig$defaul.ports)==null?void 0:_c$buildConfig$defaul2[c.platform])||((_c$runtime$currentPla=
c.runtime.currentPlatform)==null?void 0:_c$runtime$currentPla.defaultPort);
if(c.program.target!==true){
c.runtime.target=c.program.target||((_c$files$workspace$co=
c.files.workspace.config)==null?void 0:(_c$files$workspace$co2=_c$files$workspace$co.defaultTargets)==null?void 0:_c$files$workspace$co2[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."+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?void 0:_c$runtime$currentPla2.isWebHosted);


if((_c$buildConfig$defaul3=c.buildConfig.defaults)==null?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?void 0:_c$paths$project$plat[platform];
if(pDir){
isValid=true;
isConnected=pDir==null?void 0:pDir.includes==null?void 0:pDir.includes((0,_fileutils.getRealPath)(c,dir));
}
var port=((_c$buildConfig$defaul4=c.buildConfig.defaults)==null?void 0:_c$buildConfig$defaul4[platform])||((_c$runtime$currentPla3=c.runtime.currentPlatform)==null?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();}}},null,null,null,Promise);};exports.configureRuntimeDefaults=configureRuntimeDefaults;
//# sourceMappingURL=runtimeParser.js.map