diff --git a/lib/plugins/loader.js b/lib/plugins/loader.js index 83ebb71..884439c 100644 --- a/lib/plugins/loader.js +++ b/lib/plugins/loader.js @@ -52,10 +52,28 @@ class PluginsLoader { let pluCount = 0 let packageErr = [] - for (let File of files) { + for (let File of files) + { + let { name: appName, path: appPath } = File try { let tmp = await import(File.path) - if (tmp.apps) tmp = { ...tmp.apps } + // 如果当前是一个插件 + if (tmp.apps) { + // 插件主目录,在这里this.watch里已经做了判断所以不用捕获异常 + appName = `${appName}/apps` + // 插件路径 + appPath = appPath.replace(/\/index\.js$/, ""); + // 逐个遍历插件app里的js + for (let app in tmp.apps) { + // 插件目录的功能 + const curPlugin = tmp.apps[app] + // 当前目录的功能名 (apps/hello.js) + const curAppName = curPlugin.name + // 监听插件 + this.watch(appName, `${curAppName}.js`) + } + tmp = { ...tmp.apps } + } let isAdd = false lodash.forEach(tmp, (p, i) => { if (!p.prototype) return @@ -69,7 +87,7 @@ class PluginsLoader { this.collectTask(plugin.task) this.priority.push({ class: p, - key: File.name, + key: `${appName}/${p.name}.js`, name: plugin.name, priority: plugin.priority }) @@ -714,7 +732,7 @@ class PluginsLoader { } /** 黑名单群 */ if (Array.isArray(other.blackGroup) && other.blackGroup.length > 0) { - return !other.blackGroup.includes(Number(e.group_id) || e.group_id) + return other.whiteGroup.includes(Number(e.group_id) || e.group_id) } } @@ -773,6 +791,9 @@ class PluginsLoader { if (this.priority[i].key == key) { this.priority[i].class = p this.priority[i].priority = plugin.priority + // 插件更新 (ps.如果不写无法更新插件,只能更新example) + this.watcher[`${dirName}.${appName}`] = watcher + break; } } })