UNPKG

mm_connector

Version:

这是超级美眉游戏连接器,用于连接客户端和服务端,实现前后端安全通讯。

69 lines (61 loc) 1.11 kB
/** * 公共类 */ class Com { /** * 构造函数 * @param {Object} config */ constructor(config) { /** * 配置参数 */ this.config = { /** * 检索的起始目录 */ path: "./com".fullname($.runPath), /** * 检索的文件名 */ file: "index.js" }; $.push(this.config, config, true); } } /** * 加载模块 * @param {String} file 文件全名 */ Com.prototype.load = function(file) { var com = require(file); $.push($, com, true); }; /** * 运行com加载 * @param {String} path 路径 */ Com.prototype.each_load = function(path) { if (path.hasDir()) { var dirs = $.dir.get(path); var file = this.config.file; dirs.map((d) => { this.load(d + file); }); } }; /** * 卸载模块 * @param {String} file 文件全名 */ Com.prototype.unload = function(file) { delete require.cache[require.resolve(file)]; }; /** * 初始化 */ Com.prototype.init = function() { this.each_load(__dirname.fullname()); this.each_load(this.config.path); }; module.exports = Com;