UNPKG

@godspeedsystems/core

Version:

> 4th Generation Declarative Microservice Framework

57 lines (56 loc) 2.45 kB
/* * You are allowed to study this software for learning and local * development purposes only. Any other use without explicit permission by Mindgrep, is prohibited. * © 2022 Mindgrep Technologies Pvt Ltd */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "default", { enumerable: true, get: function() { return loadMappings; } }); const _path = /*#__PURE__*/ _interop_require_default(require("path")); const _configLoader = /*#__PURE__*/ _interop_require_default(require("./configLoader")); const _utils = require("./utils"); const _config = /*#__PURE__*/ _interop_require_default(require("config")); const _logger = require("../logger"); const _fs = /*#__PURE__*/ _interop_require_default(require("fs")); function _interop_require_default(obj) { return obj && obj.__esModule ? obj : { default: obj }; } let mappings; function loadMappings(mappingFolderPath) { if (typeof mappings === 'undefined' && mappingFolderPath) { if (!_fs.default.existsSync(mappingFolderPath)) { return {}; } /* iterate_yaml_directories return the object after recussively iterating the directory, and keeping it's content inside the [directory name] key so we are taking the key, on the base path of mappingFolderPath, that's the actual mapping object */ let _mappings = (0, _configLoader.default)(mappingFolderPath)[_path.default.basename(mappingFolderPath)]; // logger.debug('Unevaluated mappings: %o', _mappings); const taskLocation = { mappingPath: mappingFolderPath }; const mappingScript = (0, _utils.compileScript)(_mappings, taskLocation); const evaluatedMappings = mappingScript(_config.default, {}, {}, _mappings, {}); _logger.logger.debug('Loaded mappings: %o', Object.keys(evaluatedMappings)); mappings = evaluatedMappings; return mappings; } else { return mappings; } } // export default function loadMappings(mappingFolderPath: string) { // let mappings = iterate_yaml_directories(mappingFolderPath); // console.log('Loaded mappings: %o', mappings); // const mappingScript: Function = compileScript(mappings); // const evaluatedMappings = mappingScript(config, {}, {}, mappings, {}); // console.log('evaluatedMappings: %o', evaluatedMappings); // return evaluatedMappings; // }