var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.configureRuntimeDefaults=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));var _constants=require("../constants");




var _engineManager=require("../engineManager");
var _utils=require("../utils");
var _fileutils=require("../systemManager/fileutils");


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




var configureRuntimeDefaults=function configureRuntimeDefaults(c){var _c$files$project,_c$files$project$conf,_c$files$project$conf2,_c$buildConfig,_c$buildConfig$defaul,_c$buildConfig$defaul2,_PLATFORMS$c$platform;var _c$files$workspace$co,_c$files$workspace$co2,_c$buildConfig$defaul3,hosted;return _regenerator.default.async(function configureRuntimeDefaults$(_context){while(1){switch(_context.prev=_context.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.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])||((_PLATFORMS$c$platform=
_constants.PLATFORMS[c.platform])==null?void 0:_PLATFORMS$c$platform.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)&&_constants.WEB_HOSTED_PLATFORMS.includes(c.platform);


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.getEngineConfigByPlatform)(c,platform);
var engineRunner=(0,_engineManager.getEngineRunnerByPlatform)(c,platform);
if(engineRunner){var _c$paths$project$plat,_c$buildConfig$defaul4,_PLATFORMS$platform;
var dir=(0,_engineManager.getEngineRunnerByPlatform)(c,platform).getOriginalPlatformTemplatesDir(c);

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])||((_PLATFORMS$platform=_constants.PLATFORMS[platform])==null?void 0:_PLATFORMS$platform.defaultPort);
return{
engine:engine,
platform:platform,
isConnected:isConnected,
port:port,
isValid:isValid};

}
return null;
}).filter(function(v){return v;});
}
}return _context.abrupt("return",
true);case 13:case"end":return _context.stop();}}},null,null,null,Promise);};exports.configureRuntimeDefaults=configureRuntimeDefaults;
//# sourceMappingURL=runtimeParser.js.map