Skip to content

Commit

Permalink
Merged in release/ZZ01-148-release-3.3.0 (pull request #144)
Browse files Browse the repository at this point in the history
Release/ZZ01-148 release 3.3.0
  • Loading branch information
Michał Biarda committed Feb 23, 2022
2 parents c1e0ae2 + 1455943 commit ccc95d4
Show file tree
Hide file tree
Showing 51 changed files with 1,134 additions and 151 deletions.
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/demo export-ignore
/make export-ignore
.gitattributes export-ignore
.gitignore export-ignore
bitbucket-pipelines.yml export-ignore
Makefile.dist export-ignore
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.3.0] - 2022-02-23
### Added
- Possibility to collect property values from YAML file instead of console prompts
- Exemplary YAML files for the following templates:
- `block`
- `categoryAttributes`
- `configField`
- `emailTemplate`
- `viewModel`
- Demo GIFs in readme file
- `.gitattributes` file

### Changed
- Readme file updated with description of all options of `template:generate` command

### Fixed
- Inline edit error thrown on save for grid generated using `crud` template

### Removed
- `--dry-run` option in `template:generate` command

## [3.2.0] - 2022-01-25
### Added
- Template: `categoryAttributes`
Expand Down
42 changes: 32 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,23 @@ The purpose of this app is to automatize creation of such code, so the developer
There are other tools on the market that allows to generate Magento boilerplate code, but we went a step further.
The unique value of our tool is that it can be used with already existing codebase.
The code generated by the tool is automatically merged with current code (eg. configuration XML files, requirejs-config JS files, etc.).
Also, our aim was to generate high-quality code that uses modern PHP features and Magento coding standards.
Also, our aim was to generate high-quality code that uses modern PHP features and Magento coding standards.

## Demo

New entity with all admin CRUD actions in just a minute? Why not ;-)

### Console command

![Console command](demo/console.gif)

### Generated code

![Generated code](demo/ide.gif)

### Admin panel

![Admin panel](demo/browser.gif)

## Supported Magento versions

Expand Down Expand Up @@ -137,24 +153,30 @@ bin/codegen template:info <template>

3. Generate template:

```bin/codegen template:generate <template>```
```
bin/codegen template:generate <template>
```

For templates which type is `module` (most of them) this command must be executed on the module root folder where the `registration.php` file is.

This command must be executed on the module root folder where the `registration.php` file is.
You can also use option `--root-dir` to specify this path, if you execute it from a different location.
For templates which type is `root` this command must be executed on the Magento root folder.

Examples:
Example:

```
cd /path/to/magento/app/code/Orba/TestModule
../../../../vendor/bin/codegen template:generate block
```

```
cd /path/to/magento/vendor
bin/codegen --root-dir="/path/to/magento/app/code/Orba/TestModule" template:generate block
```
3.1. Options

| Long name | Short name | Description | Example |
|------------------|------------|---------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------|
| --root-dir | -r | If specified, code is generated on this root directory. If the directory doesn't exist, it will be created automatically. | `bin/codegen -r"/var/www/magento/app/code/Orba/TestModule" template:generate block` |
| --force-merge | -m | Use "all" to automatically run all code mergers. Use "experimental" to automatically run non-experimental code mergers. | `bin/codegen template:generate -mall block` |
| --force-override | -o | If specified, all unmerged files will be automatically overridden. | `bin/codegen template:generate -o block` |
| --yaml-path | -y | If specified, property values will be collected from YAML file instead of console prompts. | `bin/codegen -y"lib/internal/codegen/templates/block/.no-copied-config/example.yml" template:generate block` |

If specified root directory doesn't exist, it will be created automatically.

## Contribution

Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "orba/magento2-codegen",
"description": "Magento 2 Code Generator",
"version": "3.2.0",
"version": "3.3.0",
"license": "MIT",
"require": {
"php": "~7.4",
Expand All @@ -19,7 +19,8 @@
"twig/twig": "^3.0",
"nikic/php-parser": "^4.3",
"ovidigital/js-object-to-json": "^1.0",
"icanboogie/inflector": "^2.0"
"icanboogie/inflector": "^2.0",
"adbario/php-dot-notation": "^2.2"
},
"autoload": {
"psr-4": {
Expand Down
51 changes: 50 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 19 additions & 6 deletions config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,26 @@ services:
Orba\Magento2Codegen\Service\PropertyValueCollector\CollectorFactory:
arguments:
$map:
'Orba\Magento2Codegen\Model\ConstProperty': '@Orba\Magento2Codegen\Service\PropertyValueCollector\ConstCollector'
'Orba\Magento2Codegen\Model\StringProperty': '@Orba\Magento2Codegen\Service\PropertyValueCollector\StringCollector'
'Orba\Magento2Codegen\Model\ArrayProperty': '@Orba\Magento2Codegen\Service\PropertyValueCollector\ArrayCollector'
'Orba\Magento2Codegen\Model\BooleanProperty': '@Orba\Magento2Codegen\Service\PropertyValueCollector\BooleanCollector'
'Orba\Magento2Codegen\Model\ChoiceProperty': '@Orba\Magento2Codegen\Service\PropertyValueCollector\ChoiceCollector'
console:
'Orba\Magento2Codegen\Model\ConstProperty': '@Orba\Magento2Codegen\Service\PropertyValueCollector\ConstCollector'
'Orba\Magento2Codegen\Model\StringProperty': '@Orba\Magento2Codegen\Service\PropertyValueCollector\Console\StringCollector'
'Orba\Magento2Codegen\Model\ArrayProperty': '@Orba\Magento2Codegen\Service\PropertyValueCollector\Console\ArrayCollector'
'Orba\Magento2Codegen\Model\BooleanProperty': '@Orba\Magento2Codegen\Service\PropertyValueCollector\Console\BooleanCollector'
'Orba\Magento2Codegen\Model\ChoiceProperty': '@Orba\Magento2Codegen\Service\PropertyValueCollector\Console\ChoiceCollector'
yaml:
'Orba\Magento2Codegen\Model\ConstProperty': '@Orba\Magento2Codegen\Service\PropertyValueCollector\ConstCollector'
'Orba\Magento2Codegen\Model\StringProperty': '@Orba\Magento2Codegen\Service\PropertyValueCollector\Yaml\StringCollector'
'Orba\Magento2Codegen\Model\BooleanProperty': '@Orba\Magento2Codegen\Service\PropertyValueCollector\Yaml\BooleanCollector'
'Orba\Magento2Codegen\Model\ChoiceProperty': '@Orba\Magento2Codegen\Service\PropertyValueCollector\Yaml\ChoiceCollector'
'Orba\Magento2Codegen\Model\ArrayProperty': '@Orba\Magento2Codegen\Service\PropertyValueCollector\Yaml\ArrayCollector'

Orba\Magento2Codegen\Service\PropertyValueCollector\ArrayCollector:
Orba\Magento2Codegen\Service\PropertyValueCollector\Console\ArrayCollector:
calls:
- method: setCollectorFactory
arguments:
- '@Orba\Magento2Codegen\Service\PropertyValueCollector\CollectorFactory'

Orba\Magento2Codegen\Service\PropertyValueCollector\Yaml\ArrayCollector:
calls:
- method: setCollectorFactory
arguments:
Expand Down
Binary file added demo/browser.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demo/console.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demo/ide.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 33 additions & 12 deletions src/Orba/Magento2Codegen/Command/Template/GenerateCommand.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<?php

/**
* @copyright Copyright © 2021 Orba. All rights reserved.
* @copyright Copyright © 2022 Orba. All rights reserved.
* @author info@orba.co
*/

declare(strict_types=1);

namespace Orba\Magento2Codegen\Command\Template;

use InvalidArgumentException;
use Orba\Magento2Codegen\Command\AbstractCommand;
use Orba\Magento2Codegen\Model\Template;
use Orba\Magento2Codegen\Service\CodeGenerator;
use Orba\Magento2Codegen\Service\IO;
use Orba\Magento2Codegen\Service\CommandUtil\PropertyCollector as PropertyCollectorCommandUtil;
use Orba\Magento2Codegen\Service\CommandUtil\Template as TemplateCommandUtil;
use Orba\Magento2Codegen\Service\IO;
use Orba\Magento2Codegen\Service\TemplateFactory;
use Orba\Magento2Codegen\Util\PropertyBag;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -25,27 +27,35 @@

class GenerateCommand extends AbstractCommand
{
public const OPTION_DRY_RUN = 'dry-run';
public const OPTION_ROOT_DIR = 'root-dir';
public const OPTION_ROOT_DIR_SHORT = 'r';
public const OPTION_FORCE_MERGE = 'force-merge';
public const OPTION_FORCE_MERGE_SHORT = 'm';
public const OPTION_FORCE_OVERRIDE = 'force-override';
public const OPTION_FORCE_OVERRIDE_SHORT = 'o';
public const OPTION_YAML_PATH = 'yaml-path';
public const OPTION_YAML_PATH_SHORT = 'y';
public const FORCE_MERGE_ALL = 'all';
public const FORCE_MERGE_NONEXPERIMENTAL = 'nonexperimental';

private ?string $templateName;
private TemplateCommandUtil $templateUtil;
private CodeGenerator $codeGenerator;
private TemplateFactory $templateFactory;
private PropertyCollectorCommandUtil $propertyCollectorUtil;

public function __construct(
TemplateCommandUtil $templateUtil,
IO $io,
CodeGenerator $codeGenerator,
TemplateFactory $templateFactory,
PropertyCollectorCommandUtil $optionUtil,
array $inputValidators = []
) {
$this->templateUtil = $templateUtil;
$this->codeGenerator = $codeGenerator;
$this->templateFactory = $templateFactory;
$this->propertyCollectorUtil = $optionUtil;
parent::__construct($io, $inputValidators);
}

Expand All @@ -61,25 +71,30 @@ protected function configure(): void
'The template used to generate the code.'
)->addOption(
self::OPTION_ROOT_DIR,
null,
self::OPTION_ROOT_DIR_SHORT,
InputOption::VALUE_REQUIRED,
'If specified, code is generated on this root directory.',
getcwd()
)->addOption(
self::OPTION_DRY_RUN,
null,
InputOption::VALUE_NONE,
'If specified, no files will be generated.'
)->addOption(
self::OPTION_FORCE_MERGE,
null,
self::OPTION_FORCE_MERGE_SHORT,
InputOption::VALUE_REQUIRED,
sprintf(
'Use "%s" to automatically run all code mergers; '
. 'use "%s" to automatically run non-experimental code mergers',
'Use "%s" to automatically run all code mergers. '
. 'Use "%s" to automatically run non-experimental code mergers.',
self::FORCE_MERGE_ALL,
self::FORCE_MERGE_NONEXPERIMENTAL
)
)->addOption(
self::OPTION_FORCE_OVERRIDE,
self::OPTION_FORCE_OVERRIDE_SHORT,
InputOption::VALUE_NONE,
'If specified, all unmerged files will be automatically overridden.'
)->addOption(
self::OPTION_YAML_PATH,
self::OPTION_YAML_PATH_SHORT,
InputOption::VALUE_REQUIRED,
'If specified, property values will be collected from YAML file instead of console prompts.'
);
}

Expand All @@ -100,6 +115,12 @@ protected function executeInternal(InputInterface $input, OutputInterface $outpu
$this->io->getInstance()->warning('Execution stopped!');
return;
}
try {
$this->propertyCollectorUtil->handleAdditionalLogic();
} catch (InvalidArgumentException $e) {
$this->io->getInstance()->warning($e->getMessage());
return;
}
$basePropertyBag = $template->getTypeService()->getBasePropertyBag();
$this->displayHeader($template);
$this->displayTemplateDescription($template);
Expand Down
15 changes: 15 additions & 0 deletions src/Orba/Magento2Codegen/Exception/ValueInvalidException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

/**
* @copyright Copyright © 2022 Orba. All rights reserved.
* @author info@orba.co
*/

declare(strict_types=1);

namespace Orba\Magento2Codegen\Exception;

class ValueInvalidException extends \InvalidArgumentException
{

}
15 changes: 15 additions & 0 deletions src/Orba/Magento2Codegen/Exception/ValueNotAllowedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

/**
* @copyright Copyright © 2022 Orba. All rights reserved.
* @author info@orba.co
*/

declare(strict_types=1);

namespace Orba\Magento2Codegen\Exception;

class ValueNotAllowedException extends \InvalidArgumentException
{

}
15 changes: 15 additions & 0 deletions src/Orba/Magento2Codegen/Exception/ValueNotSetException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

/**
* @copyright Copyright © 2022 Orba. All rights reserved.
* @author info@orba.co
*/

declare(strict_types=1);

namespace Orba\Magento2Codegen\Exception;

class ValueNotSetException extends \InvalidArgumentException
{

}
Loading

0 comments on commit ccc95d4

Please sign in to comment.