diff --git a/.changeset/tricky-trees-wave.md b/.changeset/tricky-trees-wave.md new file mode 100644 index 00000000..034a2831 --- /dev/null +++ b/.changeset/tricky-trees-wave.md @@ -0,0 +1,5 @@ +--- +'pockethost': minor +--- + +New action: AfterPluginsLoaded diff --git a/packages/pockethost/plugin-guide.md b/packages/pockethost/plugin-guide.md index e28f5061..e60d6018 100644 --- a/packages/pockethost/plugin-guide.md +++ b/packages/pockethost/plugin-guide.md @@ -133,6 +133,10 @@ onServeAction(async ({ only }) => { | InstanceLog | A log action | logLevel, currentLogLevel, args | [example](https://github.com/pockethost/pockethost/blob/e6355c1aea2484ffba9d95110faa2af40e922855/packages/plugin-launcher-spawn/src/index.ts#L147) | 1.3.0 | | Serve | The `pockethost serve` command has been called | only[] | | 1.4.0 | +#### AfterPluginsLoaded (since 1.6.0) + +Fired after all plugins have been loaded. This is a good time to perform initialization that may depend upon other plugins. + ### Core Filters #### ServerSlugs (since 1.4.0) diff --git a/packages/pockethost/src/cli/index.ts b/packages/pockethost/src/cli/index.ts index 4241588c..c24ff88e 100755 --- a/packages/pockethost/src/cli/index.ts +++ b/packages/pockethost/src/cli/index.ts @@ -10,6 +10,7 @@ import { DEBUG, LogLevelName, LoggerService, + doAfterPluginsLoadedAction, doCliCommandsFilter, loadPlugins, } from '../common' @@ -45,6 +46,8 @@ export const main = async () => { await loadPlugins([pockethost, ...uniq(PH_PLUGINS()), ...extraPlugins]) + await doAfterPluginsLoadedAction() + program .name('pockethost') .description('Multitenant PocketBase hosting') diff --git a/packages/pockethost/src/common/plugin/action.ts b/packages/pockethost/src/common/plugin/action.ts index e17a20cc..e69756e7 100644 --- a/packages/pockethost/src/common/plugin/action.ts +++ b/packages/pockethost/src/common/plugin/action.ts @@ -4,6 +4,7 @@ import { DEBUG } from '../debug' import { InstanceFields } from '../schema' enum CoreActions { + AfterPluginsLoaded = 'core_after_plugins_loaded', Init = 'core_init', Serve = 'core_serve', AppMounted = 'core_on_app_mount', @@ -70,6 +71,9 @@ export function createCustomAction(actionName: CoreActions) { ] as const } +export const [doAfterPluginsLoadedAction, onAfterPluginsLoadedAction] = + createCustomAction(CoreActions.AfterPluginsLoaded) + export const [doRequestErrorAction, onRequestErrorAction] = createCustomActionWithContext<{ err: Error