https://github.com/ctasca/mage-bundle
Easily create Magento2/AdobeCommerce PHP/XML/JS files from a set of templates via the command-line.
https://github.com/ctasca/mage-bundle
adobe-commerce magento2 productivity-tools
Last synced: 2 months ago
JSON representation
Easily create Magento2/AdobeCommerce PHP/XML/JS files from a set of templates via the command-line.
- Host: GitHub
- URL: https://github.com/ctasca/mage-bundle
- Owner: ctasca
- License: mit
- Created: 2022-09-20T08:23:18.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-08-06T06:29:14.000Z (almost 2 years ago)
- Last Synced: 2025-12-14T18:56:28.853Z (6 months ago)
- Topics: adobe-commerce, magento2, productivity-tools
- Language: PHP
- Homepage:
- Size: 253 KB
- Stars: 26
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ctasca/mage-bundle
[](https://packagist.org/packages/phpstan/phpstan) [](https://packagist.org/packages/badges/poser)
### Easily create Magento2/AdobeCommerce PHP/XML/JS files from a set of templates via the command-line.
Allows you to define your own templates as well as the data provided at files' creation time.
## #1 Installation
```bash
composer require --dev ctasca/mage-bundle
```
### #2 Copy template files to Magento root dev/ directory
```bash
cd /vendor/ctasca/mage-bundle && composer run-script post-install-cmd
```
After executing the above command, check that dev/ directory of your Magento installation contains a mage-bundle/ directory.
### Enable the module
```bash
bin/magento module:enable Ctasca_MageBundle
```
### Run setup:upgrade command
```bash
bin/magento setup:upgrade
```
### Run setup:di:compile command (optional)
If Magento is running in production mode you will need to also run:
```bash
bin/magento setup:di:compile
```
## Available commands
```bash
bin/magento magebundle:module:create
```
#### Shortcut
```bash
bin/magento m:modu:c
```
Creates a skeleton Magento module in app/code directory, generating the required registration.php and etc/module.xml files
---
```bash
bin/magento magebundle:controller:create
```
#### Shortcut
```bash
bin/magento m:cont:c
```
Creates a Controller namespace and Action class in specified module.
Developer is prompted to choose a router (either standard or admin), and an Action template from the ones available in mage-bundle/http-controller or mage-bundle/adminhtml-http-controller directories.
---
```bash
bin/magento magebundle:etc:xml:create
```
#### Shortcut
```bash
bin/magento m:e:x:c
```
Creates an XML file in Company/Module/etc directory. Templates can be chosen after specifying the area where the template applies to.
---
```bash
bin/magento magebundle:model:set:create
```
#### Shortcut
```bash
bin/magento m:m:s:c
```
Creates a Model, Resource Model and Collection classes in specified Company/Module.
---
```bash
bin/magento magebundle:repository:create
```
#### Shortcut
```bash
bin/magento m:r:c
```
Creates all the required class for a Repository in specified Company/Module.
IMPORTANT: In order to create a repository a model implementing an interface must exist.
If you need a Repository when creating a model-set with the command magebundle:model:set:create you can choose a template that will also create a Model implementing an interface
This command creates the following:
- An API Interface for the repository
- An API Data Interface for the model (if it doesn't exist)
- An API Data Search Result Interface
- The repository Model implementing the repository Interface
Do not forget to add the preferences to your di.xml for the repository classes once created. For example:
```xml
```
---
```bash
bin/magento magebundle:model:create
```
#### Shortcut
```bash
bin/magento m:mode:c
```
Creates a Model class in specified Company/Module. There is also the template to create an interface instead of a class.
---
```bash
bin/magento magebundle:block:create
```
#### Shortcut
```bash
bin/magento m:b:c
```
Creates a template Block class in specified Company/Module.
---
```bash
bin/magento magebundle:helper:create
```
#### Shortcut
```bash
bin/magento m:h:c
```
Creates a Helper class in specified Company/Module.
---
```bash
bin/magento magebundle:customer-data:create
```
#### Shortcut
```bash
bin/magento m:cu:c
```
Creates a CustomerData class in specified Company/Module.
---
```bash
bin/magento magebundle:view-model:create
```
#### Shortcut
```bash
bin/magento m:v:c
```
Creates a View Model class in specified Company/Module.
---
```bash
bin/magento magebundle:observer:create
```
#### Shortcut
```bash
bin/magento m:o:c
```
Creates an Observer class in specified Company/Module.
---
```bash
bin/magento magebundle:plugin:create
```
#### Shortcut
```bash
bin/magento m:p:c
```
Creates a Plugin class in specified Company/Module.
---
```bash
bin/magento magebundle:cron:create
```
#### Shortcut
```bash
bin/magento m:cr:c
```
Creates a Cron class in specified Company/Module.
---
```bash
bin/magento magebundle:console-command:create
```
#### Shortcut
```bash
bin/magento m:cons:c
```
Creates a Console Command class in specified Company/Module.
---
```bash
bin/magento magebundle:data-patch:create
```
#### Shortcut
```bash
bin/magento m:d:c
```
Creates a Setup Data Patch class in specified Company/Module.
---
```bash
bin/magento magebundle:schema-patch:create
```
#### Shortcut
```bash
bin/magento m:s:c
```
Creates a Setup Schema Patch class in specified Company/Module.
---
```bash
bin/magento magebundle:api-interface:create
```
#### Shortcut
```bash
bin/magento m:a:c
```
Creates an API interface in specified Company/Module. Templates can be chosen after specifying the area where the template applies to.
For functional API interfaces, the generated file will be created in the Company/Module/Api directory
For data API interfaces, the generated file will be created in the Company/Module/Api/Data directory
---
```bash
bin/magento magebundle:jquery-widget:create
```
#### Shortcut
```bash
bin/magento m:j:c
```
Creates a JQuery widget file in specified Company/Module. JS file will be created in the specified module's view/$AREA/web/js directory.
---
```bash
bin/magento magebundle:ui-component:create
```
#### Shortcut
```bash
bin/magento m:u:c
```
Creates an Ui Component JS file in specified Company/Module. JS file will be created in the specified module's view/$AREA/web/js directory.
---
```bash
bin/magento magebundle:logger:create
```
#### Shortcut
```bash
bin/magento m:l:c
```
Creates a Logger Handler and Logger classes files in specified Company/Module.
Log filename can be specified when executing this command.
---
```bash
bin/magento magebundle:js:mixin:create
```
#### Shortcut
```bash
bin/magento m:j:m:c
```
Creates a JS mixin file in specified Company/Module. JS file will be created in the specified module's view/$AREA/web/js directory.
---
```bash
bin/magento magebundle:exception:create
```
#### Shortcut
```bash
bin/magento m:e:c
```
Creates an Exception class in specified Company/Module.
## Utilities commands
```bash
bin/magento magebundle:util:encryptor
```
#### Shortcut
```bash
bin/magento m:u:e
```
Encrypts/Decrypts a string using Magento crypt key
## Setting custom working directory
By default, MageBundle creates files in the app/code directory and in the specified module's namespace
It is possible, to change this behaviour by creating a json file named pwd.json in the $MAGENTO-ROOT/dev/mage-bundle directory and specifying the directory (relative to magento root) where files will be created when executing MageBundle commands.
This can be useful, for example, when developing a module which is not located in app/code directory
### Important:
The directory specified in pwd.json must end with a forward-slash
#### pwd.json example:
```json
{
"pwd" : "packages/my-package/"
}
```
## About template files:
Template files are written in PHP version 8.1.
For example the http-get-action-json-result.tpl.php contains the following
{{php}}
declare(strict_types=1);namespace {{namespace}};
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\Controller\Result\Json;class {{class_name}} implements HttpGetActionInterface
{
/**
* @param RequestInterface $request
* @param JsonFactory $jsonFactory
*/
public function __construct(
private readonly RequestInterface $request,
private readonly JsonFactory $jsonFactory
){}/**
* @return Json
*/
public function execute(): Json
{
$jsonResponse = $this->jsonFactory->create();
return $jsonResponse->setData([]);
}
}
To set your own templates just place them in the MAGENTO_ROOT/dev/mage-bundle/$TEMPLATES_DIRECTORY/ directory and choose the template when executing the magebundle create commands.
Note: When executing the magebundle:etc:xml:create command, files are generated with the same name as the template file.
To create your own templates, use the filename for the xml file to be generated appending __$STRING to the template filename.
For example to define your own global acl.xml template, create, for example, the template file naming like so: acl__custom.tpl.xml. Then simply place it in the dev/mage-bundle/etc/global directory and select it when executing the create command.
IMPORTANT: If a filename already exists in a module's directory, the create command will not be executed and an error is output to the console.
This is to prevent overwriting an existing file.
For a list of the templates defined within the module go to...
[The repository wiki page](https://github.com/ctasca/mage-bundle/wiki)
## Templates Data Provider
It is possible to define your own templates as well as the data that are passed when these are generated.
In order to do so, simply create a JSON file in the MAGENTO_ROOT/dev/mage-bundle/custom-data/#path-to-template# directory, naming the file exactly as the template file that is being generated and defining a JSON Object with setter methods as keys and their corresponding values.
As an example, for XML files generated in Company/Module/etc directories, custom data should be stored in MAGENTO_ROOT/dev/mage-bundle/custom-data/etc/#area#/#template_name#.tpl.json
#### Example
```json
{
"setTestNamespace" : "\\Ctasca\\MageBundle\\Test",
"setCustomDataArray" : ["First Value", "Second Value"]
}
```
After creating this JSON file, it will be possible to use the placeholder {{test_namespace}} in a template file.
As setCustomDataArray provides an array, this will be imploded with PHP_EOL separator. To use it in your template files you would use the placeholder: {{custom_data_array}}