feat: inject config folder

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2020-02-24 16:25:16 +08:00
parent 9fd4b51d98
commit d7e8b05573
2 changed files with 10 additions and 5 deletions

View File

@ -1,20 +1,22 @@
import { Container } from "@ms/container";
export namespace plugin {
/**
* MiaoScript Plugin
*/
export const Plugin = Symbol("Plugin");
/**
* MiaoScript Plugin
*/
export const PluginFolder = Symbol("PluginFolder");
/**
* Runtime Plugin Instance
*/
export const PluginInstance = Symbol("PluginInstance");
/**
* MiaoScript Plugin Manager
* MiaoScript Plugin Manager Symbol
*/
export const PluginManager = Symbol("PluginManager");
/**
* MiaoScript Plugin Manager
* MiaoScript Plugin Manager Interface
*/
export interface PluginManager {
scan(folder: string): void;

View File

@ -12,6 +12,8 @@ class MiaoScriptCore {
private Console: Console;
@inject(task.TaskManager)
private taskManager: task.TaskManager;
@inject(plugin.PluginFolder)
private pluginFolder: string;
@inject(plugin.PluginManager)
private pluginManager: plugin.PluginManager;
@ -38,7 +40,7 @@ class MiaoScriptCore {
loadPlugins() {
let loadPluginStartTime = new Date().getTime()
console.log(`Initialization MiaoScript Plugin System. Please wait...`)
this.pluginManager.scan('plugins');
this.pluginManager.scan(this.pluginFolder);
this.pluginManager.build();
this.pluginManager.load();
this.pluginManager.enable();
@ -78,6 +80,7 @@ function initialize() {
let corePackageStartTime = new Date().getTime()
container.bind(ContainerInstance).toConstantValue(container);
container.bind(plugin.PluginInstance).toConstantValue(base.getInstance());
container.bind(plugin.PluginFolder).toConstantValue('plugins');
let type = detectServer();
console.info(`Detect Compatible Server set ServerType to ${type} ...`)
container.bind(server.ServerType).toConstantValue(type);