# 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: ```bash ./scripts/validate-cli-structure.sh ``` ### validate-commands.sh Validates command files: - Checks for required exports - Verifies name and run properties - Validates toolbox usage - Checks for descriptions Usage: ```bash ./scripts/validate-commands.sh ``` ### validate-templates.sh Validates EJS template syntax: - Checks balanced EJS tags - Validates tag syntax - Detects common errors - Verifies template variables Usage: ```bash ./scripts/validate-templates.sh ``` ### test-cli-build.sh Tests CLI build process: - Validates dependencies - Runs TypeScript compilation - Tests CLI execution - Runs test suites Usage: ```bash ./scripts/test-cli-build.sh ``` ## 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: ```bash Read: /path/to/skills/gluegun-patterns/templates/commands/basic-command.ts.ejs ``` Use validation: ```bash 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) ## Related Resources - Gluegun Documentation: https://infinitered.github.io/gluegun/ - GitHub Repository: https://github.com/infinitered/gluegun - EJS Templates: https://ejs.co/ ## 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.