Skip to content

Latest commit

Β 

History

History
98 lines (71 loc) Β· 3.29 KB

File metadata and controls

98 lines (71 loc) Β· 3.29 KB

Hi @Willem,

Great question! I've recently optimized the official scaffolding tool to make creating Answer plugins much easier. Let me show you how to create a minimal Route plugin with the improved tool.

Recommended Solution: Use the Optimized Scaffolding Tool

The optimized scaffolding tool now handles everything automatically, making plugin creation much simpler:

# Install the tool (package name is create-answer-plugin)
npm install -g create-answer-plugin@beta
# or use npx (recommended)
npx create-answer-plugin@beta create hello-route

Note: The package name is create-answer-plugin, but you can use either create-answer-plugin or answer-plugin as the command (both work!).

The tool automatically:

  • βœ… Generates all required files with correct structure
  • βœ… Creates the Go wrapper file (required for registration)
  • βœ… Sets up proper go.mod with all dependencies
  • βœ… Generates i18n files with correct structure
  • βœ… Installs the plugin to your Answer project
  • βœ… Handles all the boilerplate code

This makes creating plugins much faster and eliminates common setup errors!

Installation Steps

Using the scaffolding tool is the recommended and easiest way:

# 1. Create the plugin (both commands work)
npx create-answer-plugin@beta create hello-route
# or: npx answer-plugin@beta create hello-route
# Select: Standard UI Plugin β†’ Route
# Enter route path: /hello

# 2. Navigate to your Answer project
cd /path/to/answer

# 3. Install the plugin (automatically handles registration)
npx create-answer-plugin@beta install hello-route
# or: npx answer-plugin@beta install hello-route

# The install command automatically:
# - Adds plugin import to main.go
# - Adds replace directive to go.mod
# - Runs go mod tidy
# - Merges i18n resources

# 4. Install frontend dependencies and build
cd /path/to/answer/ui
pnpm pre-install
pnpm build

# 5. Build and run Answer
cd /path/to/answer
go run ./cmd/answer/main.go run -C ./answer-data

The plugin will be available at http://localhost:80/hello (or your configured port).

Common Issues & Solutions

  1. Plugin not showing up:

    • Ensure it's in ui/src/plugins/ (plural)
    • Check that the Go wrapper file exists
    • Verify the plugin is imported in main.go
  2. Route not accessible:

    • Verify route field in info.yaml starts with /
    • Check i18n resources are merged: go run ./cmd/answer/main.go i18n
  3. Build errors:

    • Ensure go.mod has correct dependencies
    • Run go mod tidy after adding the plugin

Resources

Summary

The optimized scaffolding tool (create-answer-plugin or answer-plugin) handles all the complex setup automatically, including:

  • Correct file structure and paths
  • Go wrapper generation
  • Plugin registration
  • Dependency management
  • i18n configuration

This makes creating Answer plugins much easier and faster. I'd strongly recommend using it - it will save you a lot of time!

Let me know if you need any clarification or run into issues! πŸš€