Skip to content

Commit 19b701e

Browse files
committed
docs: update plugin development guide to clarify global vs resource-level plugins
AdminForth/1439/add-global-plugins
1 parent e56c6a7 commit 19b701e

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

adminforth/documentation/docs/tutorial/10-Advanced/01-plugin-development.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,11 @@ To ensure that plugin activates before some other plugins set `activationOrder`
512512
513513
## Making plugin global
514514
515-
If you want to make your plugin to be global and add it to the main `index.ts` in `globalPlugins` section, you need to use `pluginsScope: 'global'` and `modifyGlobalConfig` instead of `modifyResourceConfig`:
515+
Each plugin should define a scope: resource-level or global level.
516+
* Resource-level plugins should be used when plugin instance works only with one resource config or it's fields. Instances of resource-scope plugins should be installed into "plugins' field of resource config.
517+
* All other plugins should be global-scoped. Such plugins are installed to `globalPlugins` of root adminforth config. They might modify configs of many resources like default AuditLog plugin or use several database resources to store data like default Agent plugin.
518+
519+
To make your plugin global, you need to use `pluginsScope: 'global'` and `modifyGlobalConfig` instead of `modifyResourceConfig`
516520
517521
518522
```ts title="./your-global-plugin/index.ts"

adminforth/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,10 @@ class AdminForth implements IAdminForth {
296296
for (let pluginInstance of resource.plugins || []) {
297297
afLogger.trace(`🔌 Found plugin: ${pluginInstance.constructor.name} for resource ${resource.resourceId}`);
298298
if (pluginInstance.pluginsScope === 'global') {
299-
throw new Error(formatHugePluginError(`Move plugin ${pluginInstance.constructor.name} to index.ts config.globalPlugins array`));
299+
throw new Error(formatHugePluginError(`Please move plugin ${pluginInstance.constructor.name} instance to index.ts config.globalPlugins array.
300+
Details: Previously adminforth had only resource-level plugins. To keep project structure clean, in recent version of adminforth we introduced globalPlugins.
301+
Global plugins are installed on whole application and not only one resource (like agent, audit logs etc)
302+
`));
300303
}
301304
allPluginInstances.push({pi: pluginInstance, resource});
302305
}

0 commit comments

Comments
 (0)