Skip to content

Commit

Permalink
integrated subsplit command into zf3
Browse files Browse the repository at this point in the history
  • Loading branch information
kilip committed Oct 31, 2018
1 parent e52cefc commit 5cadc3e
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 186 deletions.
11 changes: 1 addition & 10 deletions module/Core/bin/yawik
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@ if (!class_exists('Core\Module', true)) {
}
}

use Core\Console\Application;
use Core\Yawik;
use Symfony\Component\Dotenv\Dotenv;

if(is_file($file =getcwd().'/.env')){
$env = new Dotenv();
$env->load($file);
}
$mvc = Yawik::initApplication();

$app = new Application($mvc->getServiceManager());
$app->run();
Yawik::runApplication(getcwd().'/config/config.php');
14 changes: 12 additions & 2 deletions module/Core/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Core;

use Core\Controller\Console\AssetsInstallController;
use Core\Controller\Console\SubsplitController;
use Core\Factory\Controller\AdminControllerFactory;
use Core\Factory\Controller\FileControllerFactory;
use Core\Factory\Controller\LazyControllerFactory;
Expand Down Expand Up @@ -196,6 +197,15 @@
'action' => 'index'
]
]
],
'subsplit' => [
'options' => [
'route' => 'subsplit [--heads=] [--tags=] [--skip-update] [--dry-run] [--verbose|-v] [<module>]',
'defaults' => [
'controller' => SubsplitController::class,
'action' => 'index'
]
]
]
],
],
Expand Down Expand Up @@ -267,7 +277,6 @@
'Core/Listener/Notification' => [\Core\Listener\NotificationListener::class,'factory'],
'Tracy' => [Tracy::class,'factory'],
Service\EntityEraser\DefaultEntityLoaderListener::class => Service\EntityEraser\DefaultEntityLoaderListenerFactory::class,
AssetsInstallController::class => [ AssetsInstallController::class,'factory'],
),
'abstract_factories' => array(
'Core\Factory\OptionsAbstractFactory',
Expand Down Expand Up @@ -335,7 +344,8 @@
'Core/File' => FileControllerFactory::class,
'Core/Content' => LazyControllerFactory::class,
Controller\Console\PurgeController::class => Controller\Console\PurgeControllerFactory::class,
AssetsInstallController::class => [AssetsInstallController::class,'factory']
AssetsInstallController::class => [AssetsInstallController::class,'factory'],
SubsplitController::class => [SubsplitController::class,'factory'],

],
),
Expand Down
76 changes: 0 additions & 76 deletions module/Core/src/Console/Application.php

This file was deleted.

24 changes: 0 additions & 24 deletions module/Core/src/Console/ConsoleCommandProviderInterface.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,57 +1,115 @@
<?php

/**
* YAWIK
*
* @filesource
* @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de)
* @license MIT
*/

namespace Core\Console;
namespace Core\Controller\Console;

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 Interop\Container\ContainerInterface;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Process;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Finder\Finder;
use Doctrine\Common\Util\Inflector;
use Symfony\Component\Process\Process;
use Zend\Mvc\Console\Controller\AbstractConsoleController;
use Zend\Console\Request as ConsoleRequest;

/**
* Class SubsplitCommand.
* Class SubsplitController
*
* @codeCoverageIgnore
* @package Core\Controller\Console
* @author Anthonius Munthi <me@itstoni.com>
* @since 0.32.0
*/
class SubsplitCommand extends Command
class SubsplitController extends AbstractConsoleController
{
// @todo Change this into git@github.com:cross-solution/yawik.git repo when make a pull request
const SOURCE = 'git@github.com:kilip/yawik.git';

const TARGET = 'git@github.com:yawik';

private $workdir;

private $tree;

private $dryRun = false;

/**
* @var OutputInterface
*/
private $output;

private $workdir;
/**
* @var SymfonyStyle
*/
private $io;

private $tree;
public function __construct()
{
$this->output = new ConsoleOutput();

}

protected function configure()
static public function factory(ContainerInterface $container)
{
return new static();
}

/**
* @return OutputInterface
*/
public function getOutput(): OutputInterface
{
return $this->output;
}

/**
* @param OutputInterface $output
*/
public function setOutput(OutputInterface $output): void
{
$this->output = $output;
}

public function indexAction()
{
$this->setName('dev:subsplit')
->addArgument('package', InputArgument::OPTIONAL, 'Module to subsplit', null)
->addOption('heads', null, InputOption::VALUE_OPTIONAL, 'Repository Heads', 'develop')
->addOption('skip-update', 's', InputOption::VALUE_NONE, 'Skip subsplit update')
->addOption('tags', null, InputOption::VALUE_OPTIONAL, 'Repository tags to include', null)
;
$this->workdir = getcwd();
/* @var ConsoleRequest $request */
$this->buildTree();
$workdir = $this->workdir;
$request = $this->getRequest();
$this->io = $io = new SymfonyStyle(new ArrayInput([]),$this->output);
$filter = $request->getParam('module',null);
$filter = null === $filter ? array() : explode(',', $filter);
$skipUpdate = $request->getParam('skip-update');
$heads = $request->getParam('heads','develop');
$tags = $request->getParam('tags',null);
if($request->getParam('verbose') || $request->getParam('v')){
$this->getOutput()->setVerbosity(OutputInterface::VERBOSITY_DEBUG);
}


$this->dryRun = $request->getParam('dry-run');
$tree = $this->tree;

if (!is_dir($dir = $workdir.'/.subsplit')) {
$this->runCommand('git subsplit init '.static::SOURCE);
} elseif (!$skipUpdate) {
$this->runCommand('git subsplit update '.static::SOURCE);
}

foreach ($tree as $name => $config) {
if (count($filter) > 0 && !in_array($name, $filter)) {
continue;
}
$io->newLine();
$io->writeln("<fg=green>Processing <fg=yellow;options=bold>${name}</> module</>");
$this->publish($config['path'], $config['repo'], $heads, $tags);
}
}

protected function buildTree()
private function buildTree()
{
$dir = getcwd().'/module';
if (!is_dir($dir)) {
Expand All @@ -75,34 +133,6 @@ protected function buildTree()
$this->tree = $tree;
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$this->buildTree();
$this->output = $output;
$workdir = $this->workdir;
$filter = $input->getArgument('package');
$filter = null === $filter ? array() : explode(',', $filter);

$tree = $this->tree;


if (!is_dir($dir = $workdir.'/.subsplit')) {
$this->runCommand('git subsplit --debug init '.static::SOURCE);
} elseif (!$input->getOption('skip-update')) {
$this->runCommand('git subsplit --debug update '.static::SOURCE);
}

$heads = $input->getOption('heads');
$tags = $input->getOption('tags');
foreach ($tree as $name => $config) {
if (count($filter) > 0 && !in_array($name, $filter)) {
continue;
}
$this->output->writeln("processing <comment>$name</comment>");
$this->publish($config['path'], $config['repo'], $heads, $tags);
}
}

private function publish($path, $repo, $heads = 'master', $tag = null)
{
$command = array(
Expand All @@ -120,23 +150,36 @@ private function publish($path, $repo, $heads = 'master', $tag = null)
$command[] = $path.':'.$repo;

$command = implode(' ', $command);
//$this->output->writeln("<comment>$command</comment>");
$this->runCommand($command);
}

private function runCommand($command)
{
if($this->io->getVerbosity() === OutputInterface::VERBOSITY_DEBUG){
$command.=' --debug';
$this->io->writeln("Executing: <info>$command</info>");
}
if($this->dryRun){
return;
}
//@codeCoverageIgnoreStart
$process = new Process($command, $this->workdir);
$process->setTimeout(null);
$process->run(array($this, 'handleProcessRun'));
//@codeCoverageIgnoreEnd
}

/**
* @param string $type
* @param string $buffer
* @codeCoverageIgnore
*/
public function handleProcessRun($type, $buffer)
{
$contents = '<info>output:</info> '.$buffer;
$contents = $buffer;
if (Process::ERR == $type) {
$contents = '<error>error:</error> '.$buffer;
$contents = $buffer;
}
$this->output->write($contents);
$this->io->write($contents);
}
}
}
Loading

0 comments on commit 5cadc3e

Please sign in to comment.