Seed CLISeed CLI

Plugins

Extend your CLI with reusable, distributable plugins.

Plugins let you package commands and extensions into reusable, distributable npm packages. They're the primary mechanism for sharing functionality across CLI projects.

Defining a Plugin

seedcli-plugin-docker/src/index.ts
import { definePlugin, command, flag } from '@seedcli/core'

export default definePlugin({
  name: 'docker',
  description: 'Docker integration for Seed CLI',
  version: '1.0.0',
  seedcli: '>=1.0.0',  // Required Seed CLI version

  commands: [
    command({
      name: 'docker-build',
      description: 'Build a Docker image',
      flags: {
        tag: flag({ type: 'string', alias: 't', description: 'Image tag' }),
        push: flag({ type: 'boolean', description: 'Push after build' }),
      },
      run: async ({ flags, system, print }) => {
        const tag = flags.tag ?? 'latest'
        await system.exec(`docker build -t ${tag} .`)
        if (flags.push) {
          await system.exec(`docker push ${tag}`)
        }
        print.success(`Built image: ${tag}`)
      },
    }),
  ],

  extensions: [
    {
      name: 'docker-check',
      setup: async (seed) => {
        await seed.system.whichOrThrow('docker')
      },
    },
  ],

})

Plugin Options

OptionTypeDescription
namestringPlugin identifier (required)
descriptionstringHuman-readable description
versionstringPlugin version (required)
seedclistringRequired Seed CLI semver range
peerPluginsRecord<string, string>Required peer plugin versions
commandsCommand[]Commands to register
extensionsExtensionConfig[]Extensions to register
templatesstringPath to templates directory
defaultsRecord<string, unknown>Default configuration values

Loading Plugins

By Name

const runtime = build('my-cli')
  .plugin('seedcli-plugin-docker')
  .create()

Resolves from node_modules. The package must export a plugin as its default export.

Multiple Plugins

build('my-cli')
  .plugin(['seedcli-plugin-docker', 'seedcli-plugin-aws'])

From Directory

build('my-cli')
  .plugins('./plugins')

Scans the directory for subdirectories (including symlinks from npm link) and imports each as a plugin module.

Peer Plugin Dependencies

Plugins can declare dependencies on other plugins:

definePlugin({
  name: 'deploy',
  version: '1.0.0',
  peerPlugins: {
    docker: '>=1.0.0',
    aws: '>=2.0.0',
  },
  // ...
})

If a required peer plugin is missing or the version doesn't match, a PluginValidationError is thrown at startup.

Version Constraints

The seedcli field constrains which versions of Seed CLI the plugin supports:

definePlugin({
  name: 'my-plugin',
  version: '1.0.0',
  seedcli: '>=1.0.0 <2.0.0',
  // ...
})

Publishing a Plugin

Plugins are standard npm packages. Follow these conventions:

  1. Name your package seedcli-plugin-<name>
  2. Export the plugin as the default export
  3. Specify seedcli version range
  4. Include "seedcli-plugin" keyword in package.json
package.json
{
  "name": "seedcli-plugin-docker",
  "version": "1.0.0",
  "keywords": ["seedcli-plugin"],
  "main": "dist/index.js",
  "peerDependencies": {
    "@seedcli/core": ">=1.0.0"
  }
}

Declare @seedcli/core as a peer dependency, not a regular dependency, to avoid version conflicts.

On this page