# SixShop Maker Bundle A powerful command-line tool for generating SixShop extension boilerplate code, designed to streamline the development process within the SixShop ecosystem. [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![PHP Version](https://img.shields.io/badge/PHP-%3E%3D8.0-blue)](https://php.net) [![ThinkPHP](https://img.shields.io/badge/ThinkPHP-%5E8.1-green)](https://github.com/top-think/framework) ## ๐Ÿš€ 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) ```bash # Install as development dependency composer require six-shop/maker-bundle --dev # Or install globally composer global require six-shop/maker-bundle ``` ### Manual Installation ```bash # Clone the repository git clone https://github.com/sixshop/maker-bundle.git cd maker-bundle # Install dependencies composer install ``` ## ๐ŸŽฏ Usage ### Quick Start ```bash # 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 ```bash $ 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 ```bash # 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 ```bash # 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** ```bash Error: Target path not writable ``` Solution: Ensure write permissions on target directory **Missing Dependencies** ```bash Error: Composer autoload not found ``` Solution: Run `composer install` first **Invalid Package Names** ```bash 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: ```bash # 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 ```bash # 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](LICENSE) file for details. ## ๐Ÿ‘ฅ Authors - **runphp** - *Initial work* - [runphp@qq.com](mailto:runphp@qq.com) ## ๐Ÿ”— Links - [SixShop Framework](https://github.com/sixshop) - [ThinkPHP Framework](https://github.com/top-think/framework) - [Symfony Console](https://symfony.com/doc/current/console.html) ## ๐Ÿ“ 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**