README.md 7.3 KB

SixShop Maker Bundle

A powerful command-line tool for generating SixShop extension boilerplate code, designed to streamline the development process within the SixShop ecosystem.

PHP Version ThinkPHP

🚀 Features

  • Automated Code Generation: Generates complete SixShop extension structure with zero manual coding
  • Intelligent Detection: Automatically detects existing extensions and pre-fills configuration values
  • Smart Path Management: Flexible target path selection with validation and confirmation
  • Template-Based: Uses configurable PHP templates for consistent code generation
  • PSR-4 Compliant: Generates proper namespace structure and autoloading configuration
  • Interactive CLI: User-friendly command-line interface with helpful prompts and validation

📋 Requirements

  • PHP: >= 8.0
  • Composer: Latest version recommended
  • ThinkPHP Framework: ^8.1
  • Symfony Console: ^7.3

🛠 Installation

Via Composer (Recommended)

# Install as development dependency
composer require six-shop/maker-bundle --dev

# Or install globally
composer global require six-shop/maker-bundle

Manual Installation

# Clone the repository
git clone https://github.com/sixshop/maker-bundle.git
cd maker-bundle

# Install dependencies
composer install

🎯 Usage

Quick Start

# If installed locally
php vendor/bin/sixshop-maker

# If installed globally
sixshop-maker

# Or directly
php bin/sixshop-maker

Interactive Workflow

The tool guides you through a step-by-step process:

  1. Target Path Selection: Choose where to generate your extension
  2. Package Configuration: Set package name, namespace, and description
  3. Extension Settings: Configure extension ID and metadata
  4. File Generation: Automatic creation of all necessary files

Example Session

$ php vendor/bin/sixshop-maker

请输入扩展生成的目标路径 [/current/path]: ./my-extension
将在以下路径生成扩展: /full/path/to/my-extension
确认使用此路径? [yes]

请输入Composer包名 (例如: six-shop/hello): my-vendor/awesome-extension
请输入包描述 [A SixShop extension package]: My awesome SixShop extension
请输入命名空间 (例如: SixShop\Hello\) [MyVendor\AwesomeExtension\]: 
请输入扩展ID [my-vendor-awesome-extension]: 

✅ 扩展创建完成!

📁 Generated Structure

The tool creates a complete extension structure:

my-extension/
├── composer.json          # Package configuration
├── .gitignore            # Git ignore rules
├── src/
│   └── Extension.php     # Main extension class
├── route/
│   ├── api.php          # API routes
│   └── admin.php        # Admin routes
├── config.php           # Extension configuration
└── info.php            # Extension metadata

🔧 Smart Features

Existing Extension Detection

The tool automatically detects existing composer.json files and offers:

  • One-click regeneration with existing configuration
  • Pre-filled prompts with current values
  • Seamless updates for existing extensions

Path Intelligence

  • Automatic validation of target paths
  • Permission checking before generation
  • Directory creation if paths don't exist
  • Confirmation prompts for safety

Namespace Handling

  • Consistent formatting across all generated files
  • PSR-4 compliance with proper autoloading
  • JSON-safe escaping in configuration files
  • User-friendly display in terminal interfaces

🎨 Customization

Templates

All generated files use PHP templates located in /templates/:

  • composer.json.tpl.php - Package configuration
  • src/Extension.php.tpl.php - Main extension class
  • .gitignore.tpl.php - Git ignore rules
  • route/api.php.tpl.php - API routes
  • route/admin.php.tpl.php - Admin routes
  • config.php.tpl.php - Configuration file
  • info.php.tpl.php - Metadata file

Available Variables

Templates have access to these variables:

  • $name - Package name (e.g., "vendor/package")
  • $namespace - PHP namespace (e.g., "Vendor\Package\")
  • $id - Extension ID (e.g., "vendor-package")
  • $description - Package description

🏗 Architecture

Components

  • Maker - Main command controller and user interaction
  • ComposerGenerator - Handles composer.json generation and detection
  • DirectoryGenerator - Creates directory structure
  • GitignoreGenerator - Generates .gitignore files
  • PhpCodeGenerator - Creates PHP source files from templates

Design Patterns

  • Generator Pattern: Specialized classes for each artifact type
  • Template Method: Consistent generation workflow
  • Single Responsibility: Each generator handles one concern
  • Command Pattern: CLI interface implementation

🔄 Workflow Examples

Creating a New Extension

# Start the maker
php vendor/bin/sixshop-maker

# Follow prompts
Target Path: ./my-new-extension
Package Name: sixshop/payment-gateway
Namespace: SixShop\PaymentGateway\
Extension ID: sixshop-payment-gateway

# Result: Complete extension ready for development

Regenerating an Existing Extension

# Run in directory with existing composer.json
php vendor/bin/sixshop-maker

# Tool detects existing configuration
Found existing composer.json: ./composer.json
Package: sixshop/payment-gateway
Namespace: SixShop\PaymentGateway\

# Confirm regeneration
Use existing configuration? [yes]

# Files updated with current templates

🐛 Troubleshooting

Common Issues

Permission Errors

Error: Target path not writable

Solution: Ensure write permissions on target directory

Missing Dependencies

Error: Composer autoload not found

Solution: Run composer install first

Invalid Package Names

Error: Package name format incorrect

Solution: Use format "vendor/package" with lowercase and hyphens

Debug Mode

For verbose output, use PHP's built-in debugging:

# Enable error reporting
php -d display_errors=1 vendor/bin/sixshop-maker

🤝 Contributing

We welcome contributions! Please see our contributing guidelines:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

Development Setup

# Clone and setup
git clone https://github.com/sixshop/maker-bundle.git
cd maker-bundle
composer install

# Run the tool locally
php bin/sixshop-maker

📄 License

This project is licensed under the MIT License. See the LICENSE file for details.

👥 Authors

🔗 Links

📝 Changelog

v1.0.0

  • Initial release with core generation features
  • Smart existing extension detection
  • Flexible path management
  • Template-based file generation
  • PSR-4 compliant namespace handling

Made with ❤️ for the SixShop community