!104 未被迁移至喵崽的功能:插件apps内js热更新

Merge pull request !104 from 曉K/master
This commit is contained in:
Kokomi 2023-09-07 18:23:54 +00:00 committed by Gitee
commit a1a7f6b44a
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 24 additions and 3 deletions

View File

@ -52,10 +52,28 @@ class PluginsLoader {
let pluCount = 0 let pluCount = 0
let packageErr = [] let packageErr = []
for (let File of files) { for (let File of files)
{
let { name: appName, path: appPath } = File
try { try {
let tmp = await import(File.path) 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 let isAdd = false
lodash.forEach(tmp, (p, i) => { lodash.forEach(tmp, (p, i) => {
if (!p.prototype) return if (!p.prototype) return
@ -69,7 +87,7 @@ class PluginsLoader {
this.collectTask(plugin.task) this.collectTask(plugin.task)
this.priority.push({ this.priority.push({
class: p, class: p,
key: File.name, key: `${appName}/${p.name}.js`,
name: plugin.name, name: plugin.name,
priority: plugin.priority priority: plugin.priority
}) })
@ -773,6 +791,9 @@ class PluginsLoader {
if (this.priority[i].key == key) { if (this.priority[i].key == key) {
this.priority[i].class = p this.priority[i].class = p
this.priority[i].priority = plugin.priority this.priority[i].priority = plugin.priority
// 插件更新 (ps.如果不写无法更新插件只能更新example)
this.watcher[`${dirName}.${appName}`] = watcher
break;
} }
} }
}) })