Files
gh-vanman2024-cli-builder-p…/skills/gluegun-patterns
2025-11-30 09:04:14 +08:00
..
2025-11-30 09:04:14 +08:00
2025-11-30 09:04:14 +08:00
2025-11-30 09:04:14 +08:00
2025-11-30 09:04:14 +08:00
2025-11-30 09:04:14 +08:00

Gluegun Patterns Skill

Comprehensive patterns and templates for building TypeScript-powered CLI applications using the Gluegun toolkit.

Overview

This skill provides everything needed to build production-ready CLI tools with Gluegun, including:

  • Command templates for common patterns
  • Template system with EJS
  • Filesystem operation examples
  • HTTP/API utilities
  • Interactive prompts
  • Plugin architecture
  • Validation scripts
  • Real-world examples

Structure

gluegun-patterns/
├── SKILL.md                    # Main skill documentation
├── README.md                   # This file
├── scripts/                    # Validation and helper scripts
│   ├── validate-cli-structure.sh
│   ├── validate-commands.sh
│   ├── validate-templates.sh
│   ├── test-cli-build.sh
│   └── template-helpers.ts
├── templates/                  # EJS templates
│   ├── commands/              # Command templates
│   │   ├── basic-command.ts.ejs
│   │   ├── generator-command.ts.ejs
│   │   └── api-command.ts.ejs
│   ├── extensions/            # Toolbox extensions
│   │   ├── custom-toolbox.ts.ejs
│   │   └── helper-functions.ts.ejs
│   ├── plugins/               # Plugin templates
│   │   ├── plugin-template.ts.ejs
│   │   └── plugin-with-commands.ts.ejs
│   └── toolbox/               # Toolbox examples
│       ├── template-examples.ejs
│       ├── prompt-examples.ts.ejs
│       └── filesystem-examples.ts.ejs
└── examples/                  # Complete examples
    ├── basic-cli/            # Simple CLI
    ├── plugin-system/        # Plugin architecture
    └── template-generator/   # Advanced templates

Features

Command Templates

  • basic-command.ts.ejs - Simple command structure with parameters
  • generator-command.ts.ejs - Template-based file generator
  • api-command.ts.ejs - HTTP/API interaction command

Extension Templates

  • custom-toolbox.ts.ejs - Custom toolbox extension pattern
  • helper-functions.ts.ejs - Reusable utility functions

Plugin Templates

  • plugin-template.ts.ejs - Basic plugin structure
  • plugin-with-commands.ts.ejs - Plugin that adds commands

Toolbox Examples

  • template-examples.ejs - EJS template patterns
  • prompt-examples.ts.ejs - Interactive prompt patterns
  • filesystem-examples.ts.ejs - Filesystem operation examples

Validation Scripts

validate-cli-structure.sh

Validates Gluegun CLI directory structure:

  • Checks required files (package.json, tsconfig.json)
  • Verifies directory structure (src/, src/commands/)
  • Validates dependencies (gluegun)
  • Checks for entry point

Usage:

./scripts/validate-cli-structure.sh <cli-directory>

validate-commands.sh

Validates command files:

  • Checks for required exports
  • Verifies name and run properties
  • Validates toolbox usage
  • Checks for descriptions

Usage:

./scripts/validate-commands.sh <commands-directory>

validate-templates.sh

Validates EJS template syntax:

  • Checks balanced EJS tags
  • Validates tag syntax
  • Detects common errors
  • Verifies template variables

Usage:

./scripts/validate-templates.sh <templates-directory>

test-cli-build.sh

Tests CLI build process:

  • Validates dependencies
  • Runs TypeScript compilation
  • Tests CLI execution
  • Runs test suites

Usage:

./scripts/test-cli-build.sh <cli-directory>

Examples

Basic CLI

Simple CLI demonstrating core patterns:

  • Command structure
  • Parameter handling
  • Template generation
  • Print utilities

See: examples/basic-cli/

Plugin System

Extensible CLI with plugin architecture:

  • Plugin discovery
  • Plugin loading
  • Custom extensions
  • Plugin commands

See: examples/plugin-system/

Template Generator

Advanced template patterns:

  • Multi-file generation
  • Conditional templates
  • Template composition
  • Helper functions

See: examples/template-generator/

Usage

In Agent Context

When building CLI tools, agents will automatically discover this skill based on keywords:

  • "CLI tool"
  • "command structure"
  • "template system"
  • "Gluegun"
  • "plugin architecture"

Direct Reference

Load templates:

Read: /path/to/skills/gluegun-patterns/templates/commands/basic-command.ts.ejs

Use validation:

Bash: /path/to/skills/gluegun-patterns/scripts/validate-cli-structure.sh ./my-cli

Best Practices

  1. Command Organization

    • One command per file
    • Clear naming conventions
    • Descriptive help text
  2. Template Design

    • Keep templates simple
    • Use helper functions for logic
    • Document variables
  3. Error Handling

    • Validate user input
    • Check API responses
    • Provide helpful messages
  4. Plugin Architecture

    • Use unique namespaces
    • Document plugin APIs
    • Handle missing dependencies
  5. Testing

    • Test commands in isolation
    • Validate template output
    • Mock external dependencies

Security

  • Never hardcode API keys (use environment variables)
  • Validate all user input
  • Sanitize file paths
  • Check permissions before file operations
  • Use placeholders in templates (e.g., your_api_key_here)

Requirements

  • Node.js 14+ or TypeScript 4+
  • Gluegun package
  • EJS (included with Gluegun)
  • fs-jetpack (included with Gluegun)
  • enquirer (included with Gluegun)

Skill Validation

This skill meets all requirements:

  • 4 validation scripts
  • 10 EJS templates (TypeScript and universal)
  • 3 complete examples with documentation
  • SKILL.md with proper frontmatter
  • No hardcoded API keys or secrets
  • Clear "Use when" trigger contexts

Contributing

When adding new patterns:

  1. Create template in appropriate directory
  2. Add validation if needed
  3. Document in SKILL.md
  4. Include usage examples
  5. Run validation scripts
  6. Test with real CLI project

License

Patterns and templates are provided as examples for building CLI tools.