opti: 完善插件机制

This commit is contained in:
suxiaoxin 2017-09-28 20:40:29 +08:00
parent 6047d4cf8c
commit 1ce0692c31
4 changed files with 12 additions and 4 deletions

1
.gitignore vendored
View File

@ -41,3 +41,4 @@ dev/
.tags
.tags1
tsconfig.json
client/plugin-module.js

View File

@ -1 +1 @@
module.exports = null
module.exports = {qsso : require('plugins/yapi-plugin-qsso/client.js')}

View File

@ -79,13 +79,20 @@ pluginModule = {
bindHook: bindHook,
emitHook: emitHook
}
let pluginModuleList;
try{
pluginModuleList = require('./plugin-module.js');
}catch(err){pluginModuleList = {}}
let pluginModuleList = require('./plugin-module.js');
config.plugins.forEach(plugin=>{
if (!plugin) return null;
if (!plugin.enable) return null;
if(plugin.client){
pluginModuleList[plugin.name].call(pluginModule, plugin)
if(pluginModuleList[plugin.name] && typeof pluginModuleList[plugin.name] === 'function'){
pluginModuleList[plugin.name].call(pluginModule, plugin)
}
}
})

View File

@ -27,7 +27,7 @@ function fileExist (filePath){
function initPlugins(){
var scripts = [] ;
if(config.plugins && Array.isArray(config.plugins)){
if(config.plugins && Array.isArray(config.plugins) && config.plugins.length){
config.plugins = config.plugins.filter(item=>{
return fileExist(path.resolve(__dirname, 'node_modules/yapi-plugin-' + item + '/client.js'))
})