var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=exports.taskRnvDoctor=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _toConsumableArray2=_interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));var _lodash=_interopRequireDefault(require("lodash.get"));
var _logger=require("../../core/systemManager/logger");
var _constants=require("../../core/constants");
var _engineManager=require("../../core/engineManager");
var _runtimeParser=require("../../core/configManager/runtimeParser");
var _fileutils=require("../../core/systemManager/fileutils");
var _schemaParser=require("../../core/schemaManager/schemaParser");




var configTargets=[
'workspace.config',
'workspace.project.config',
'workspace.appConfig.configs',
'project.config',
'appConfig.configs'];


var taskRnvDoctor=function taskRnvDoctor(c,parentTask,originTask){var configPaths,errMsg,hasErrors;return _regenerator.default.async(function taskRnvDoctor$(_context){while(1){switch(_context.prev=_context.next){case 0:
(0,_logger.logTask)('taskRnvDoctor');_context.next=3;return _regenerator.default.awrap(


(0,_runtimeParser.configureRuntimeDefaults)(c));case 3:_context.next=5;return _regenerator.default.awrap(
(0,_engineManager.executeTask)(c,_constants.TASK_APP_CONFIGURE,parentTask,originTask));case 5:_context.next=7;return _regenerator.default.awrap(
(0,_runtimeParser.configureRuntimeDefaults)(c));case 7:

configPaths=[];

configTargets.forEach(function(target){
var tPath=(0,_lodash.default)(c.paths,target);

if(tPath){
if(Array.isArray(tPath)){
configPaths.push.apply(configPaths,(0,_toConsumableArray2.default)(tPath));
}else{
configPaths.push(tPath);
}
}
});

errMsg='RENATIVE JSON SCHEMA VALIDITY CHECK:\n\n';
hasErrors=false;
configPaths.forEach(function(cPath){
if((0,_fileutils.fsExistsSync)(cPath)){
var cObj=(0,_fileutils.readObjectSync)(cPath);var _validateRenativeJson=

(0,_schemaParser.validateRenativeJsonSchema)(cObj),_validateRenativeJson2=(0,_slicedToArray2.default)(_validateRenativeJson,2),valid=_validateRenativeJson2[0],ajv=_validateRenativeJson2[1];
if(!valid){
hasErrors=true;

errMsg+=(0,_logger.chalk)().yellow("\nInvalid schema in "+

cPath+". ISSUES:\n\n");
ajv.errors.forEach(function(err){
errMsg+=(0,_logger.chalk)().yellow(
(0,_logger.chalk)().grey(err.dataPath===''?'/':err.dataPath)+": "+err.message+" "+
Object.keys(err.params).map(function(k){return"=> "+(0,_logger.chalk)().red(err.params[k]);}).join('\n')+"\n");
});
}
}
});

if(!hasErrors){
errMsg+=(0,_logger.chalk)().green("PASSED "+configPaths.length+" files");
}






(0,_logger.logToSummary)(errMsg);case 14:case"end":return _context.stop();}}},null,null,null,Promise);};exports.taskRnvDoctor=taskRnvDoctor;var _default=


{
description:'Checks validity and config health of your project',
fn:taskRnvDoctor,
task:_constants.TASK_DOCTOR,
params:_constants.PARAMS.withBase(),
platforms:[],
isGlobalScope:true};exports.default=_default;
//# sourceMappingURL=task.rnv.doctor.js.map