Skip to Content
🎉 Hyperse Wizard has been published.

Plugin

The Plugin System provides a modular architecture that allows the Wizard framework to be extended with additional functionality through dynamically loaded plugins.

DefinePlugin

Parameters:
NameTypeDefault
pluginPlugin<CommandMapping, Result, GlobalFlags, ExtendedGlobalFlags>

The plugin to define.

Returns:
Plugin<CommandMapping, Result, GlobalFlags, ExtendedGlobalFlags>

Plugin

NameTypeDefault
nameLocaleMessageResolver

The name of the plugin.

localeMessagesDeepPartial<{ en: PluginLocaleMessages; zh: PluginLocaleMessages; }>

The locale messages provided by the plugin.

setup(cli: PluginSetupWizard<NameToContext, GlobalFlags>, ctx: PluginContext) => PluginSetupWizard<Result, ExtendedGlobalFlags>

The setup method of the plugin. This function is called when the plugin is registered with the Wizard instance. It receives the current Wizard instance and the plugin context, and should return a (possibly extended) Wizard instance.

Plugin Architecture

The plugin system is designed with security and encapsulation in mind. When a plugin’s setup method is called, it receives a restricted Wizard instance (PluginSetupWizard) that only exposes the essential methods needed for plugin functionality.

PluginSetupWizard Type

The PluginSetupWizard type is a restricted version of the full Wizard instance that excludes three critical methods:

  • use - Plugin registration method
  • on - Event listening method
  • parse - Command parsing and execution method

This restriction prevents plugins from:

  • Registering additional plugins during setup (which could cause infinite loops)
  • Setting up event listeners during setup (which could interfere with core execution)
  • Triggering command parsing during setup (which could cause premature execution)

Available Methods in PluginSetupWizard

Plugins can access these methods and properties during setup:

  • Command Register: register()
  • Configuration: name, description, version, locale, i18n
  • Global Settings: globalFlags, commandMap, commandChain flags()
  • Utilities: interceptor(), errorHandler()

Advanced Usage

To separate handlers from the plugin definition, you can use the definePlugin utility function:

// @filename: @hyperse/wizard/dist/index.d.ts import { } from '@hyperse/wizard'; const = ({ : 'deploy plugin', : helpMessages, : (, ) => { return .(deployCmd); }, });
Last updated on