ms/packages/api/src/plugin.ts

191 lines
4.6 KiB
TypeScript
Raw Normal View History

import { injectable } from '@ccms/container'
export namespace plugin {
/**
* MiaoScript Plugin
*/
export const Plugin = Symbol("Plugin")
/**
* MiaoScript Plugin Folder
*/
export const PluginFolder = Symbol("PluginFolder")
/**
* Runtime Plugin Instance
*/
export const PluginInstance = Symbol("PluginInstance")
/**
* MiaoScript Plugin Manager Interface
*/
@injectable()
export abstract class PluginManager {
abstract scan(folder: string): void
abstract build(): void
abstract loadFromFile(file: string, scanner?: plugin.PluginScanner): Plugin
abstract load(...args: any[]): void
abstract enable(...args: any[]): void
abstract disable(...args: any[]): void
abstract reload(...args: any[]): void
abstract getPlugin(name: string): plugin.Plugin
abstract getPlugins(): Map<string, plugin.Plugin>
}
export const PluginScanner = Symbol("PluginScanner")
/**
*
*/
export interface PluginLoadMetadata {
/**
*
*/
type: string
/**
*
*/
file?: string
/**
*
*/
instance?: any
/**
*
*/
metadata?: PluginMetadata
/**
*
*/
scanner: PluginScanner
/**
*
*/
loader?: PluginLoader
/**
*
*/
loaded?: boolean
[key: string]: any
}
/**
*
*/
export interface PluginScanner {
/**
*
*/
type: string
/**
*
* @param target
*/
scan(target: any): PluginLoadMetadata[]
/**
*
* @param target
*/
read(target: any): PluginLoadMetadata
/**
*
* @param target
*/
load(target: PluginLoadMetadata): PluginLoadMetadata
}
export const PluginLoader = Symbol("PluginLoader")
/**
*
*/
export interface PluginLoader {
/**
*
*/
type: string
/**
*
* @param target
* @param result
*/
require(loadMetadata: PluginLoadMetadata): PluginLoadMetadata
/**
*
* @param metadata
*/
build(metadata: PluginMetadata): Plugin
/**
* Load
* @param plugin
*/
2020-09-17 09:44:48 +00:00
load?(plugin: Plugin): void
/**
* Enable
* @param plugin
*/
2020-09-17 09:44:48 +00:00
enable?(plugin: Plugin): void
/**
* Disable
* @param plugin
*/
2020-09-17 09:44:48 +00:00
disable?(plugin: Plugin): void
/**
* Reload
* @param plugin
*/
2020-09-17 09:44:48 +00:00
reload?(plugin: Plugin): void
}
export interface Plugin {
description: PluginMetadata
logger: Console
load(): void
enable(): void
disable(): void
}
export interface BaseMetadata {
/**
*
*/
name?: string
/**
*
*/
servers?: string[]
}
export interface PluginMetadata extends BaseMetadata {
/**
*
*/
name?: string
/**
*
*/
prefix?: string
/**
* 1.0.0
*/
version?: string
/**
* Unknow
*/
author?: string | string[]
/**
*
*/
depends?: string[]
/**
*
*/
nativeDepends?: string[]
/**
* __filename
*/
source: string
/**
* ioc MiaoScript
*/
type?: string
/**
*
*/
loadMetadata?: PluginLoadMetadata
/**
*
*/
target?: any
}
}