"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.taskRnvDoctor = exports["default"] = void 0;var _lodash = _interopRequireDefault(require("lodash.get"));
var _logger = require("../../core/systemManager/logger");
var _constants = require("../../core/constants");
var _taskManager = require("../../core/taskManager");
var _runtimeManager = require("../../core/runtimeManager");
var _fileutils = require("../../core/systemManager/fileutils");
var _schemaManager = require("../../core/schemaManager");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { "default": obj };}function _slicedToArray(arr, i) {return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();}function _nonIterableRest() {throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _iterableToArrayLimit(arr, i) {var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];if (_i == null) return;var _arr = [];var _n = true;var _d = false;var _s, _e;try {for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {_arr.push(_s.value);if (i && _arr.length === i) break;}} catch (err) {_d = true;_e = err;} finally {try {if (!_n && _i["return"] != null) _i["return"]();} finally {if (_d) throw _e;}}return _arr;}function _arrayWithHoles(arr) {if (Array.isArray(arr)) return arr;}function _toConsumableArray(arr) {return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();}function _nonIterableSpread() {throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _unsupportedIterableToArray(o, minLen) {if (!o) return;if (typeof o === "string") return _arrayLikeToArray(o, minLen);var n = Object.prototype.toString.call(o).slice(8, -1);if (n === "Object" && o.constructor) n = o.constructor.name;if (n === "Map" || n === "Set") return Array.from(o);if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);}function _iterableToArray(iter) {if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);}function _arrayWithoutHoles(arr) {if (Array.isArray(arr)) return _arrayLikeToArray(arr);}function _arrayLikeToArray(arr, len) {if (len == null || len > arr.length) len = arr.length;for (var i = 0, arr2 = new Array(len); i < len; i++) {arr2[i] = arr[i];}return arr2;}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 configTargets = [
'workspace.config',
'workspace.project.config',
'workspace.appConfig.configs',
'project.config',
'appConfig.configs'];


var taskRnvDoctor = /*#__PURE__*/function () {var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(c, parentTask, originTask) {var configPaths, errMsg, hasErrors;return regeneratorRuntime.wrap(function _callee$(_context) {while (1) {switch (_context.prev = _context.next) {case 0:
            (0, _logger.logTask)('taskRnvDoctor');_context.next = 3;return (


              (0, _runtimeManager.configureRuntimeDefaults)(c));case 3:_context.next = 5;return (
              (0, _taskManager.executeTask)(c, _constants.TASK_APP_CONFIGURE, parentTask, originTask));case 5:_context.next = 7;return (
              (0, _runtimeManager.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, _toConsumableArray(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, _schemaManager.validateRenativeJsonSchema)(cObj),_validateRenativeJson2 = _slicedToArray(_validateRenativeJson, 2),valid = _validateRenativeJson2[0],ajv = _validateRenativeJson2[1];
                if (!valid) {
                  hasErrors = true;
                  // console.log('ERROR', ajv.errors);
                  errMsg += (0, _logger.chalk)().yellow("\nInvalid schema in ".concat(
                  // cPath}. ISSUES: ${JSON.stringify(ajv.errors, null, 2)}\n`);
                  cPath, ". ISSUES:\n\n"));
                  ajv.errors.forEach(function (err) {
                    errMsg += (0, _logger.chalk)().yellow("".concat(
                    (0, _logger.chalk)().grey(err.dataPath === '' ? '/' : err.dataPath), ": ").concat(err.message, " ").concat(
                    Object.keys(err.params).map(function (k) {return "=> ".concat((0, _logger.chalk)().red(err.params[k]));}).join('\n'), "\n"));
                  });
                }
              }
            });

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

            // const [valid, ajv] = validateRuntimeObjectSchema(c);
            // if (!valid) {
            //     console.log('ERROR', ajv.errors);
            // }

            (0, _logger.logToSummary)(errMsg);case 14:case "end":return _context.stop();}}}, _callee);}));return function taskRnvDoctor(_x, _x2, _x3) {return _ref.apply(this, arguments);};}();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