@leafer/plugin
Advanced tools
+3
-3
| { | ||
| "name": "@leafer/plugin", | ||
| "version": "1.0.0-beta.2", | ||
| "version": "1.0.0-beta.4", | ||
| "description": "@leafer/plugin", | ||
@@ -22,7 +22,7 @@ "author": "Chao (Leafer) Wan", | ||
| "dependencies": { | ||
| "@leafer/debug": "1.0.0-beta.2" | ||
| "@leafer/debug": "1.0.0-beta.4" | ||
| }, | ||
| "devDependencies": { | ||
| "@leafer/interface": "1.0.0-beta.2" | ||
| "@leafer/interface": "1.0.0-beta.4" | ||
| } | ||
| } |
+17
-9
@@ -7,15 +7,18 @@ import { IPlugin, IObject } from '@leafer/interface' | ||
| export const Plugin = { | ||
| powers: {} as IObject, | ||
| export const PluginManager = { | ||
| power: {} as IObject, | ||
| list: [] as IPlugin[] | ||
| } | ||
| export function usePlugin(plugin: IPlugin) { | ||
| export function usePlugin(plugin: IPlugin, power?: IObject) { | ||
| Plugin.list.push(plugin) | ||
| if (!power) power = PluginManager.power | ||
| PluginManager.list.push(plugin) | ||
| const realParams: IObject = {} | ||
| if (plugin.import) { | ||
| const realParams: IObject = {} | ||
| plugin.import.forEach(item => { | ||
| if (Plugin.powers[item]) { | ||
| realParams[item] = Plugin.powers[item] | ||
| if (power[item]) { | ||
| realParams[item] = power[item] | ||
| } else { | ||
@@ -25,7 +28,12 @@ debug.error(item + ' non-existent') | ||
| }) | ||
| plugin.run(realParams) | ||
| } else { | ||
| debug.error('no dependencies') | ||
| debug.warn('no import') | ||
| } | ||
| try { | ||
| plugin.run(realParams) | ||
| } catch (e) { | ||
| debug.error(e) | ||
| } | ||
| } |
2494
4.48%27
22.73%+ Added
+ Added
- Removed
- Removed
Updated