Skip to content

Commit

Permalink
add new command, generator and test for creating standalone plugins (#3)
Browse files Browse the repository at this point in the history
* add new command, generator and test for creating standalone plugins

* Fix when latest dockware version is SW5 Version

* add simple phpunit test setup

* add files for phpunit

* fix shopware version

* change resolver

* add command for run php unit

* require phpstan

* update shopware version

* update skeleton for plugin

* add phpstan

* update plugin readme

Co-authored-by: Peter Roj <[email protected]>
  • Loading branch information
pureware and JuicyLung91 authored Nov 11, 2022
1 parent ee69be7 commit cf24008
Show file tree
Hide file tree
Showing 23 changed files with 1,101 additions and 3 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
},
"require-dev": {
"phpunit/phpunit": "^8.0|^9.3",
"symfony/var-dumper": "^6.0"
"symfony/var-dumper": "^6.0",
"phpstan/phpstan": "^1.9"
}
}
61 changes: 60 additions & 1 deletion composer.lock

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

6 changes: 6 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
level: 8
paths:
- ./src
excludePaths:
- ./src/Resources/*
57 changes: 57 additions & 0 deletions src/Command/Common/RunPhpStanCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Pureware\PurewareCli\Command\Common;

use Pureware\PurewareCli\Maker\Entity\EntityMaker;
use Pureware\PurewareCli\Maker\Entity\HydratorMaker;
use Pureware\PurewareCli\Maker\Entity\Many2ManyMaker;
use Pureware\PurewareCli\Maker\Entity\TranslationMaker;
use Pureware\PurewareCli\Maker\Migration\MigrationMaker;
use Pureware\PurewareCli\Resolver\NamespaceResolverInterface;
use Pureware\TemplateGenerator\TreeBuilder\Directory\Directory;
use Pureware\TemplateGenerator\TreeBuilder\Directory\DirectoryCollection;
use Pureware\TemplateGenerator\TreeBuilder\File\File;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Helper\TableSeparator;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Process\Process;
use Symfony\Component\Serializer\SerializerInterface;

class RunPhpStanCommand extends \Pureware\PurewareCli\Command\AbstractMakeCommand
{
protected static $defaultName = 'phpstan';

public function __construct(string $name = null)
{
parent::__construct($name);
}

protected function configure()
{
$this
->setName(self::$defaultName)
->setDescription('Run PHP stan for src and tests')
->addOption('options', null, InputOption::VALUE_OPTIONAL, 'The options that are added to the phpstan command as string i.e. --options="-c phpstan.neo"', '-c phpstan.neon');
parent::configure();
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$command = sprintf('vendor/bin/phpstan analyse src Tests -c phpstan.neon %s', $input->getOption('options'));

$cli = Process::fromShellCommandline($command, null, null, null, 240);
$cli->setTty(true);

$cli->run(function ($type, $line) use ($output) {
$output->write($line);
});

return Command::SUCCESS;
}

}
68 changes: 68 additions & 0 deletions src/Command/Common/RunPhpUnitCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace Pureware\PurewareCli\Command\Common;

use Pureware\PurewareCli\Maker\Entity\EntityMaker;
use Pureware\PurewareCli\Maker\Entity\HydratorMaker;
use Pureware\PurewareCli\Maker\Entity\Many2ManyMaker;
use Pureware\PurewareCli\Maker\Entity\TranslationMaker;
use Pureware\PurewareCli\Maker\Migration\MigrationMaker;
use Pureware\PurewareCli\Resolver\NamespaceResolverInterface;
use Pureware\TemplateGenerator\TreeBuilder\Directory\Directory;
use Pureware\TemplateGenerator\TreeBuilder\Directory\DirectoryCollection;
use Pureware\TemplateGenerator\TreeBuilder\File\File;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Helper\TableSeparator;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Process\Process;
use Symfony\Component\Serializer\SerializerInterface;

class RunPhpUnitCommand extends \Pureware\PurewareCli\Command\AbstractMakeCommand
{
protected static $defaultName = 'test:phpunit';

public function __construct(string $name = null)
{
parent::__construct($name);
}

protected function configure()
{
$this
->setName(self::$defaultName)
->setDescription('Run PHP Unit inside the docker container')
->addArgument('pluginName', InputArgument::OPTIONAL, 'The name of the plugin you want to test. (optional, default will be the current plugin)', null)
->addOption('container', 'c', InputOption::VALUE_OPTIONAL , 'The docker container name', 'shop_plugin')
->addOption('options', null, InputOption::VALUE_OPTIONAL , 'The options that are added to the phpunit command as string i.e. --options="--testdox"', '--colors=always --testdox');
parent::configure();
}

protected function execute(InputInterface $input, OutputInterface $output): int
{

$pluginName = $input->getArgument('pluginName');
if (!$input->getArgument('pluginName')) {
$resolver = $this->getNamespaceResolver();
$pluginName = $resolver->getPluginName();
}

$command = sprintf('docker exec %s vendor/bin/phpunit --configuration="%s" %s', $input->getOption('container'), 'custom/plugins/' . $pluginName, $input->getOption('options'));

$cli = Process::fromShellCommandline($command, null, null, null, 240);
$cli->setTty(true);

$cli->run(function ($type, $line) use ($output) {
$output->write($line);
});



return Command::SUCCESS;
}

}
45 changes: 45 additions & 0 deletions src/Command/New/NewPluginCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
namespace Pureware\PurewareCli\Command\New;

use Pureware\PurewareCli\Generator\Plugin\PluginGenerator;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class NewPluginCommand extends Command
{
private array $allowedTypes = ['plugin', 'project'];

protected function configure()
{
$this
->setName('new:plugin')
->addArgument('pluginName', InputArgument::OPTIONAL, 'The name of a plugin', null)
->addOption('shopwareVersion', 's', InputArgument::OPTIONAL, sprintf('Shopware version i.e. %s. If not set the latest Shopware tag will be used', PluginGenerator::DEFAULT_VERSION), null)
->addOption('force', 'f', InputOption::VALUE_NONE, 'Override files. Be careful when using!')
->addOption('workingDir', null, InputOption::VALUE_OPTIONAL, 'The path were you want to create the new plugin', null)
->addOption('git', null, InputOption::VALUE_NONE, 'Initialize a git repo and first commit with a branch. Set a remote url afterwards.')
->addOption('branch', null, InputOption::VALUE_OPTIONAL, 'Init branch name for git', 'main')
->setDescription('Create a new standalone plugin with a ready to use boilerplate.');
parent::configure();
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln(PHP_EOL."<fg=blue>
_____ _ _ _____ ______
| __ \| | | | __ \| ____|
| |__) | | | | |__) | |__
| ___/| | | | _ /| __|
| | | |__| | | \ \| |____
|_| \____/|_| \_\______| </>".PHP_EOL.PHP_EOL);

$output->writeln('Pure installer');

return (new PluginGenerator())->generate($input, $output);

return self::SUCCESS;
}
}
11 changes: 11 additions & 0 deletions src/Generator/GeneratorInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Pureware\PurewareCli\Generator;

use Symfony\Component\Console\Input\Input;
use Symfony\Component\Console\Output\Output;

interface GeneratorInterface
{
public function generate(Input $input, Output $output): int;
}
Loading

0 comments on commit cf24008

Please sign in to comment.