MCPcopy
hub / github.com/alibaba/lowcode-engine / LowCodePluginManager

Class LowCodePluginManager

packages/designer/src/plugin/plugin-manager.ts:28–224  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26const RESERVED_EVENT_PREFIX = ['designer', 'editor', 'skeleton', 'renderer', 'render', 'utils', 'plugin', 'engine', 'editor-core', 'engine-core', 'plugins', 'event', 'events', 'log', 'logger', 'ctx', 'context'];
27
28export class LowCodePluginManager implements ILowCodePluginManager {
29 private plugins: ILowCodePluginRuntime[] = [];
30
31 pluginsMap: Map<string, ILowCodePluginRuntime> = new Map();
32 pluginContextMap: Map<string, LowCodePluginContext> = new Map();
33
34 private pluginPreference?: PluginPreference = new Map();
35
36 contextApiAssembler: ILowCodePluginContextApiAssembler;
37
38 constructor(contextApiAssembler: ILowCodePluginContextApiAssembler, readonly viewName = 'global') {
39 this.contextApiAssembler = contextApiAssembler;
40 }
41
42 _getLowCodePluginContext = (options: IPluginContextOptions) => {
43 const { pluginName } = options;
44 let context = this.pluginContextMap.get(pluginName);
45 if (!context) {
46 context = new LowCodePluginContext(options, this.contextApiAssembler);
47 this.pluginContextMap.set(pluginName, context);
48 }
49 return context;
50 };
51
52 isEngineVersionMatched(versionExp: string): boolean {
53 const engineVersion = engineConfig.get('ENGINE_VERSION');
54 // ref: https://github.com/npm/node-semver#functions
55 // 1.0.1-beta should match '^1.0.0'
56 return semverSatisfies(engineVersion, versionExp, { includePrerelease: true });
57 }
58
59 /**
60 * register a plugin
61 * @param pluginConfigCreator - a creator function which returns the plugin config
62 * @param options - the plugin options
63 * @param registerOptions - the plugin register options
64 */
65 async register(
66 pluginModel: IPublicTypePlugin,
67 options?: any,
68 registerOptions?: IPublicTypePluginRegisterOptions,
69 ): Promise<void> {
70 // registerOptions maybe in the second place
71 if (isLowCodeRegisterOptions(options)) {
72 registerOptions = options;
73 options = {};
74 }
75 let { pluginName, meta = {} } = pluginModel;
76 const { preferenceDeclaration, engines } = meta;
77 // filter invalid eventPrefix
78 const { eventPrefix } = meta;
79 const isReservedPrefix = RESERVED_EVENT_PREFIX.find((item) => item === eventPrefix);
80 if (isReservedPrefix) {
81 meta.eventPrefix = undefined;
82 logger.warn(`plugin ${pluginName} is trying to use ${eventPrefix} as event prefix, which is a reserved event prefix, please use another one`);
83 }
84 const ctx = this._getLowCodePluginContext({ pluginName, meta });
85 const customFilterValidOptions = engineConfig.get('customPluginFilterOptions', filterValidOptions);

Callers

nothing calls this directly

Calls 2

getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…