Magento2 - Simplified module creation
If you work with Magento, you may know that creating new modules, commands, controllers, etc. cannot be done without some tools.
A popular tool is Mage2Gen.com.
But now you can do it with the CLI, too.
Mage2Gen
Mage2Gen is a great tool to get started with a new module.
But if you already have an existing project and you want to add some new component like a command, controller, block, helper, etc., Mage2Gen is not ideal.
- Either you download the zip file from Mage2Gen and merge its contents with your existing project.
- Or you copy and paste each new/changed file into your module.
- Or you copy, paste and modify from your existing code with the risk of copy & paste errors.
PhpStorm with Magento2 plugin
The Magento2 developer team wrote a plugin for the IDE PhpStorm from JetBrains.
I do not have a license for PhpStorm. I use VS Code. So I cannot use this plugin.
Magento2-Gen-CLI
The way I solved this situation is my own Magento2 module.
It adds CLI commands that are very similar to the Laravel commands.
You can pass any required information as arguments or wait for the command to ask for it.
# Creates a new module "Mage/Sales" in the folder "app/code"
$ php bin/magento make:module
Vendor name (e.g. 'Magento'): Mage
Module name (e.g. 'Sales'): Sales
Generating files...
Module 'Mage/Sales' was created.
# Adds a new helper "Pricing" to the module "Mage/Sales"
$ php bin/magento make:helper Mage Sales Pricing
# Adds a new command "CalcPricing" to the module "Mage/Sales"
# and also adds the item entry in the file "di.xml"
$ php bin/magento make:command
Vendor name (e.g. 'Magento'): Mage
Module name (e.g. 'Sales'): Sales
Command name (e.g. 'SyncSales'): CalcPricing
Command (e.g. 'sales:sync'): sales:pricing:calc
Command description (e.g. 'Sync sales with Cloud'): Recalculate the pricing
Generating command...
Command 'CalcPricing' was created.
If you are interested, you can find more details here:
GitHub
Packagist