UNPKG

zents

Version:

ZenTS is a Node.js & TypeScript MVC-Framework for building rich web applications, released as free and open-source software under the MIT License. It is designed for building web applications with modern tools and design patterns.

73 lines 2.99 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AbstractZenFileLoader = void 0; const path_1 = require("path"); /** * The AbstractZenFileLoader acts as a base class for ZenTS's loader classes (e.g. ControllerLoader). * It's main purpose is to supply an interface to easy load modules dynamiclly and parsing them to the * extending classes in a unified way. If you write a new loader, you should use this class to load the * Node.js modules. */ class AbstractZenFileLoader { /** * Load a given module and returns an unitialized version of the module. The exported class is guessed either * by using the default export (CommonJS) or by using the modules filename to determine the exported member. * This function will throw an error when no exported member could be found. * * @param filePath Absolute path to the module file */ async loadModule(filePath) { const module = (await Promise.resolve().then(() => __importStar(require(filePath)))); const moduleKeys = Object.keys(module); const { name: filename } = path_1.parse(filePath); let classModule; if (moduleKeys.includes('default')) { classModule = module.default; } else if (moduleKeys.includes(filename)) { classModule = module[filename]; } else { throw new Error('Unable to find the exported module member. Please use default export.'); } return { key: filename.toLowerCase(), module: classModule, }; } /** * Returns all method names of a class. * * @param classObjProto The prototype of a class */ getClassMethods(classObjProto) { if (classObjProto === Object.prototype || !classObjProto) { return []; } return [ ...Object.getOwnPropertyNames(classObjProto), ...this.getClassMethods(Object.getPrototypeOf(classObjProto)), ]; } } exports.AbstractZenFileLoader = AbstractZenFileLoader; //# sourceMappingURL=AbstractZenFileLoader.js.map