细节优化

This commit is contained in:
🌌 2023-09-08 12:01:04 +08:00
parent 758ea77261
commit 4b6b547c6c
2 changed files with 22 additions and 6 deletions

View File

@ -25,6 +25,8 @@ if (!executablePath) for (const item of [
"/usr/bin/chrome",
"C:/Program Files/Google/Chrome/Application/chrome.exe",
"C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe",
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
"/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
]) if (existsSync(item)) {
executablePath = item
break

View File

@ -54,14 +54,29 @@ class PluginsLoader {
let packageErr = []
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
}
if (!p.prototype) return
isAdd = true
/* eslint-disable new-cap */
let plugin = new p()
@ -72,12 +87,11 @@ 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
})
})
if (isAdd) pluCount++
} catch (error) {
if (error.stack.includes("Cannot find package")) {