δΈζ | English
A powerful CLI tool for creating and managing plugins for the Apache Answer project. This tool provides scaffolding for both Backend Plugins and Standard UI Plugins, along with plugin lifecycle management.
- π Interactive Plugin Creation: Create plugins with an interactive CLI
- π¦ Multiple Plugin Types: Support for 7 Backend Plugin types and 4 Standard UI Plugin types
- π§ Plugin Management: List, install, and uninstall plugins
- π‘οΈ Type Safety: Built with TypeScript for better type safety
- π Security: Built-in security validation and command sanitization
- π Auto-generated Templates: Hello World examples for all plugin types
npm install -g create-answer-plugin
# or
pnpm add -g create-answer-pluginNote: The package name is create-answer-plugin, but the command is answer-plugin. You can also use create-answer-plugin as an alias.
# Both commands work: npx create-answer-plugin <command> npx answer-plugin <command>
Create a new plugin with an interactive wizard:
answer-plugin create [pluginName]
# or
answer-plugin [pluginName]Options:
pluginName(optional): Pre-fill the plugin name--path, -p: Path to Answer project (root directory)
Example:
answer-plugin create my-plugin
List all plugins in the Answer project:
answer-plugin list [path]
Options:
path(optional): Path to Answer project (defaults to current directory)
Example:
answer-plugin list answer-plugin list /path/to/answer
Install plugins to the Answer project:
answer-plugin install [plugins...] [--path <path>]
Options:
plugins(optional): Plugin names to install (defaults to all not installed plugins)--path, -p: Path to Answer project
Example:
# Install all not installed plugins answer-plugin install # Install specific plugins answer-plugin install my-plugin another-plugin
Uninstall plugins from the Answer project:
answer-plugin uninstall [plugins...] [--path <path>]
Options:
plugins(optional): Plugin names to uninstall (defaults to all installed plugins)--path, -p: Path to Answer project
Example:
# Uninstall all installed plugins answer-plugin uninstall # Uninstall specific plugins answer-plugin uninstall my-plugin another-plugin
Backend plugins extend Answer's backend functionality:
- Connector - OAuth/SSO integration plugins
- Storage - File storage plugins (e.g., S3, OSS)
- Cache - Caching plugins (e.g., Redis, Memcached)
- Search - Search engine plugins (e.g., Elasticsearch, Meilisearch)
- User Center - User management plugins
- Notification - Notification service plugins (e.g., Email, SMS)
- Reviewer - Content review plugins
Standard UI plugins extend Answer's frontend UI:
- Editor - Rich text editor plugins
- Route - Custom route/page plugins
- Captcha - Captcha verification plugins
- Render - Content rendering plugins
answer-plugin create github-connector
The tool will guide you through:
- Plugin name (pre-filled if provided)
- Answer project path
- Plugin type (Backend or Standard UI)
- Sub-type selection (e.g., Connector, Storage, etc.)
answer-plugin create my-custom-route
For Route plugins, you'll also be prompted for the route path.
# List all plugins answer-plugin list # Install all plugins answer-plugin install # Install specific plugins answer-plugin install plugin1 plugin2 # Uninstall plugins answer-plugin uninstall plugin1
The tool supports configuration through environment variables:
ANSWER_PLUGINS_PATH: Custom plugins directory path (default:ui/src/plugins)ANSWER_I18N_PATH: Custom i18n directory path (default:answer-data/i18n)GO_MOD_TIDY_TIMEOUT: Timeout forgo mod tidyin milliseconds (default: 30000)PNPM_INSTALL_TIMEOUT: Timeout forpnpm installin milliseconds (default: 120000)LOG_LEVEL: Logging level -DEBUG,INFO,WARN,ERROR,SILENT(default:INFO)
ui/src/plugins/my-plugin/
βββ my_plugin.go # Main plugin implementation
βββ info.yaml # Plugin metadata
βββ go.mod # Go module definition
βββ i18n/ # Internationalization files
β βββ en_US.yaml
β βββ zh_CN.yaml
β βββ translation.go
βββ README.md # Plugin documentation
ui/src/plugins/my-plugin/
βββ my_plugin.go # Go wrapper
βββ info.yaml # Plugin metadata
βββ Component.tsx # React component
βββ index.ts # Plugin entry point
βββ package.json # npm dependencies
βββ tsconfig.json # TypeScript config
βββ vite.config.ts # Vite config
βββ i18n/ # Internationalization files
β βββ en_US.yaml
β βββ zh_CN.yaml
β βββ index.ts
βββ README.md # Plugin documentation
# Clone the repository git clone https://github.com/answerdev/create-answer-plugin.git cd create-answer-plugin # Install dependencies pnpm install # Run in development mode pnpm dev # Build pnpm build
# Verify a single plugin pnpm verify <plugin-name> # Verify all plugins pnpm verify:all # Create all plugin types for testing pnpm create:all
-
Plugin Creation: The tool generates plugin scaffolding based on the selected type, including:
- Go implementation files (for Backend plugins)
- React/TypeScript components (for Standard UI plugins)
- Configuration files (
info.yaml,go.mod,package.json) - i18n translation files
- README documentation
-
Plugin Installation: When you run
install:- Adds plugin import to
cmd/answer/main.go - Adds
replacedirective togo.mod - Runs
go mod tidy - Merges i18n resources using
go run ./cmd/answer/main.go i18n
- Adds plugin import to
-
Plugin Uninstallation: When you run
uninstall:- Removes plugin import from
main.go - Removes
replacedirective fromgo.mod - Runs
go mod tidy - Updates i18n resources
- Removes plugin import from
The tool is built with:
- TypeScript: For type safety and better developer experience
- Error Handling: Comprehensive error handling with custom error types
- File Transactions: Atomic file operations with rollback support
- Security: Command validation and path sanitization
- Configuration Management: Centralized configuration with environment variable support
- Logging: Structured logging with configurable log levels
- Node.js >= 16
- Go >= 1.23 (for Backend plugins)
- pnpm (for Standard UI plugins)
MIT
Contributions are welcome! Please feel free to submit a Pull Request.