2019-09-07 04:23:15 +00:00
|
|
|
import { interfaces } from './interfaces'
|
|
|
|
import { METADATA_KEY } from './constants'
|
|
|
|
import { injectable, decorate } from "inversify";
|
|
|
|
import { getPluginMetadatas } from './utils'
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MiaoScript plugin
|
2019-09-10 09:22:00 +00:00
|
|
|
* @param metadata PluginMetadata
|
2019-09-07 04:23:15 +00:00
|
|
|
*/
|
2019-09-10 09:22:00 +00:00
|
|
|
export function plugin(metadata: interfaces.PluginMetadata) {
|
2019-09-07 04:23:15 +00:00
|
|
|
return function(target: any) {
|
2019-09-10 09:22:00 +00:00
|
|
|
target.description = metadata;
|
|
|
|
metadata.target = target;
|
2019-09-07 04:23:15 +00:00
|
|
|
decorate(injectable(), target);
|
2019-09-10 09:22:00 +00:00
|
|
|
Reflect.defineMetadata(METADATA_KEY.plugin, metadata, target);
|
2019-09-07 04:23:15 +00:00
|
|
|
const previousMetadata: interfaces.PluginMetadata[] = getPluginMetadatas();
|
2019-09-10 09:22:00 +00:00
|
|
|
Reflect.defineMetadata(METADATA_KEY.plugin, [metadata, ...previousMetadata], Reflect);
|
2019-09-07 04:23:15 +00:00
|
|
|
};
|
|
|
|
}
|