细节优化
This commit is contained in:
parent
758ea77261
commit
4b6b547c6c
|
@ -25,6 +25,8 @@ if (!executablePath) for (const item of [
|
||||||
"/usr/bin/chrome",
|
"/usr/bin/chrome",
|
||||||
"C:/Program Files/Google/Chrome/Application/chrome.exe",
|
"C:/Program Files/Google/Chrome/Application/chrome.exe",
|
||||||
"C:/Program Files (x86)/Microsoft/Edge/Application/msedge.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)) {
|
]) if (existsSync(item)) {
|
||||||
executablePath = item
|
executablePath = item
|
||||||
break
|
break
|
||||||
|
|
|
@ -54,14 +54,29 @@ class PluginsLoader {
|
||||||
|
|
||||||
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) {
|
if (!p.prototype) return
|
||||||
return
|
|
||||||
}
|
|
||||||
isAdd = true
|
isAdd = true
|
||||||
/* eslint-disable new-cap */
|
/* eslint-disable new-cap */
|
||||||
let plugin = new p()
|
let plugin = new p()
|
||||||
|
@ -72,12 +87,11 @@ 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
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
if (isAdd) pluCount++
|
if (isAdd) pluCount++
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.stack.includes("Cannot find package")) {
|
if (error.stack.includes("Cannot find package")) {
|
||||||
|
|
Loading…
Reference in New Issue