ms/packages/plugin/src/decorators.ts

20 lines
713 B
TypeScript
Raw Normal View History

import { interfaces } from './interfaces'
import { METADATA_KEY } from './constants'
import { injectable, decorate } from "inversify";
import { getPluginMetadatas } from './utils'
/**
* MiaoScript plugin
* @param metadata PluginMetadata
*/
export function plugin(metadata: interfaces.PluginMetadata) {
return function(target: any) {
target.description = metadata;
metadata.target = target;
decorate(injectable(), target);
Reflect.defineMetadata(METADATA_KEY.plugin, metadata, target);
const previousMetadata: interfaces.PluginMetadata[] = getPluginMetadatas();
Reflect.defineMetadata(METADATA_KEY.plugin, [metadata, ...previousMetadata], Reflect);
};
}