Skip to content

feat: Add plugin system to CLI #3783

@odinr

Description

@odinr

Is your feature request related to a problem? Please describe.
Currently, the Fusion Framework CLI has a fixed set of commands (app, portal, auth, create, disco, ai) that are hardcoded in the CLI package. This limits extensibility and makes it difficult for teams or third-party developers to add custom commands or extend CLI functionality without modifying the core CLI package.

Describe the solution you'd like
Implement a plugin system for the CLI that allows:

  1. Plugin Discovery & Loading

    • Support for plugins installed as npm packages (e.g., @equinor/fusion-framework-cli-plugin-*)
    • Support for local plugins (e.g., .fusion/plugins/ directory)
    • Plugin discovery via package.json dependencies or configuration file
    • Plugin versioning and compatibility checks
  2. Plugin API

    • Standard interface for plugins to register commands with Commander.js
    • Access to CLI utilities (logger, spinner, etc.)
    • Lifecycle hooks (before/after command execution)
    • Configuration support (plugin-specific config in .fusion/config.json or similar)
  3. Plugin Structure

    interface CliPlugin {
      name: string;
      version: string;
      description?: string;
      register(program: Command, context: CliContext): void | Promise<void>;
      // Optional lifecycle hooks
      beforeCommand?(command: string, args: string[]): void | Promise<void>;
      afterCommand?(command: string, args: string[]): void | Promise<void>;
    }
  4. Integration Points

    • Load plugins during CLI initialization (in src/cli/main.ts)
    • Register plugin commands alongside built-in commands
    • Support for plugin-specific help text and documentation
    • Plugin error handling and isolation
  5. Developer Experience

    • Clear documentation on creating plugins
    • Example plugin template/boilerplate
    • Plugin validation and error messages
    • Support for plugin development mode (hot reload during development)

Describe alternatives you've considered

  • Monorepo-only extensions: Only allow extending CLI within the monorepo - this doesn't help external developers
  • Forking the CLI: Not maintainable and creates fragmentation
  • Wrapper scripts: Workaround but doesn't integrate with CLI help, error handling, or utilities
  • Configuration-based commands: Limited flexibility compared to full plugin system

Additional context

Current CLI Structure:
The CLI uses Commander.js and currently registers commands in src/cli/commands/index.ts:

  • app - Application lifecycle commands
  • portal - Portal template commands
  • auth - Authentication commands
  • create - Project scaffolding
  • disco - Service discovery
  • ai - AI/LLM integration commands

Inspiration from Framework:
The Fusion Framework already has plugin patterns (e.g., feature flags with addPlugin()), which could serve as a reference for the CLI plugin architecture.

Use Cases:

  • Teams adding custom deployment commands specific to their infrastructure
  • Third-party tools integrating with Fusion Framework (e.g., testing frameworks, code generators)
  • Internal tools extending CLI functionality without modifying core package
  • Custom build pipelines or CI/CD integrations

Implementation Considerations:

  • Plugin security and sandboxing (if needed)
  • Plugin dependency management
  • Backward compatibility with existing commands
  • Performance impact of plugin loading
  • Plugin discovery performance (especially with many plugins)

Related:

  • Similar to how Vite, ESLint, and other tools support plugins
  • Could enable ecosystem growth around Fusion Framework CLI

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions