UNPKG

@kitmi/jacaranda

Version:

JavaScript application framework

76 lines (75 loc) 2.58 kB
/** * Load libs modules * @module Feature_Libs * * @example * * 'libs': { * '<alias>': { * npmModule: false, // whether is a npm module * options: { // module options * }, * settings: { // can override module defined settings * } * } * } */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "default", { enumerable: true, get: function() { return _default; } }); const _nodepath = /*#__PURE__*/ _interop_require_default(require("node:path")); const _utils = require("@kitmi/utils"); const _Feature = /*#__PURE__*/ _interop_require_default(require("../Feature")); const _LibModule = /*#__PURE__*/ _interop_require_default(require("../LibModule")); function _interop_require_default(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const _default = { /** * This feature is loaded at plugin stage. * @member {string} */ stage: _Feature.default.PLUGIN, /** * Load the feature. * @param {App} app - The app module object. * @param {object} entries - Lib module entries. * @returns {Promise.<*>} */ load_: async (app, entries)=>{ return (0, _utils.batchAsync_)(entries, async (config, name)=>{ let options = { configType: app.options.configType, logLevel: app.options.logLevel, ...config.options }; let { appPath, moduleMeta } = await app.tryLoadModule_(config, config.name ?? name, app.libModulesPath, `libs.[${name}]`); let lib = new _LibModule.default(app, name, appPath, { ...options, ...moduleMeta?.options, registry: moduleMeta?.registry }); lib.once('configLoaded', ()=>{ if (!_utils._.isEmpty(config.settings)) { lib.config.settings = { ...lib.config.settings, ...config.settings }; app.log('verbose', `Lib settings of [${lib.name}] is overrided.`); } }); let relativePath = _nodepath.default.relative(app.workingPath, appPath); app.log('verbose', `Loading lib [${lib.name}] from "${relativePath}" ...`); await lib.start_(); app.registerLib(lib); app.log('verbose', `Lib [${lib.name}] is loaded.`); }); } }; //# sourceMappingURL=libs.js.map