Skip to content

Commit

Permalink
[TASK] Move script definitions to plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
ochorocho committed Sep 19, 2022
1 parent 45d867a commit 8d19922
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 41 deletions.
14 changes: 0 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,6 @@
"email": "jochen.roth@b13.com"
}
],
"scripts": {
"post-root-package-install": "@tdk:setup",
"post-create-project-cmd": [
"composer tdk:help summary",
"composer tdk:help done"
],
"tdk:setup": [
"composer tdk:git clone",
"composer tdk:git config",
"composer tdk:hooks create",
"composer tdk:ddev",
"composer tdk:git template"
]
},
"repositories": {
"local-packages": {
"type": "path",
Expand Down
90 changes: 63 additions & 27 deletions packages/tdk-composer-plugin/src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,16 @@
namespace Ochorocho\TdkComposer;

use Composer\Composer;
use Composer\DependencyResolver\Operation\InstallOperation;
use Composer\Console\Application;
use Composer\EventDispatcher\EventSubscriberInterface;
use Composer\Installer\PackageEvent;
use Composer\Installer\PackageEvents;
use Composer\IO\IOInterface;
use Composer\Plugin\Capability\CommandProvider as CommandProviderCapability;
use Composer\Plugin\Capable as CapableInterface;
use Composer\Plugin\PluginEvents;
use Composer\Plugin\PluginInterface;
use Composer\Plugin\PreFileDownloadEvent;
use Composer\Script\Event;
use Composer\Script\ScriptEvents;
use Ochorocho\TdkComposer\Command\CommandProvider;
use Ochorocho\TdkComposer\Command\GitCommand;
use Ochorocho\TdkComposer\Service\GitService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;

final class Plugin implements PluginInterface, CapableInterface, EventSubscriberInterface
{
Expand All @@ -29,20 +23,33 @@ final class Plugin implements PluginInterface, CapableInterface, EventSubscriber
*/
protected $io;

/**
* @var Application $application
*/
protected $application;

public function activate(Composer $composer, IOInterface $io)
{
$this->io = $io;
$this->application = new Application();
$this->application->setAutoExit(false);
}

public static function getSubscribedEvents()
{
return [
// 'post-root-package-install' => [
// ['cloneRepository', 0]
// ],
'post-install-cmd' => [
['cloneRepository', 0]
],
'post-root-package-install' => [
['gitConfig', 10],
['createHooks', 20],
['ddevConfig', 30],
['commitTemplate', 40]
],
'post-create-project-cmd' => [
['gitConfig', 0]
],
];
}

Expand All @@ -65,24 +72,53 @@ public function uninstall(Composer $composer, IOInterface $io): void

public function cloneRepository(Event $event): int
{
$gitService = new GitService();

if ($gitService->repositoryExists()) {
$this->io->write('Repository exists! Therefore no download required.', true, IOInterface::VERBOSE);
return Command::SUCCESS;
}

$this->io->writeError('<info>Cloning TYPO3 repository. This may take a while depending on your internet connection!</info>');
$this->io->write('<info>Cloning TYPO3 repository. This may take a while depending on your internet connection!</info>');
$this->io->writeRaw('<info>Cloning TYPO3 repository. This may take a while depending on your internet connection!</info>');
$gitRemoteUrl = 'https://github.com/TYPO3/typo3.git';
if ($gitService->cloneRepository($gitRemoteUrl)) {
$event->getIO()->write('<warning>Could not download git repository ' . $gitRemoteUrl . ' </warning>');
return Command::FAILURE;
}

$input = new ArrayInput(array('command' => 'tdk:git', 'action' => 'clone'));
$this->application->run($input);
$event->getComposer()->getRepositoryManager()->createRepository('path', ['url' => 'typo3-core/typo3/sysext/*'], 'typo3-core-packages');

return Command::SUCCESS;
}

public function gitConfig(Event $event): int
{
$input = new ArrayInput(array('command' => 'tdk:git', 'action' => 'config'));
$this->application->run($input);

return Command::SUCCESS;
}

public function createHooks(Event $event): int
{
$input = new ArrayInput(array('command' => 'tdk:hooks', 'action' => 'create'));
$this->application->run($input);

return Command::SUCCESS;
}

public function ddevConfig(Event $event): int
{
$input = new ArrayInput(array('command' => 'tdk:ddev'));
$this->application->run($input);

return Command::SUCCESS;
}

public function commitTemplate(Event $event): int
{
$input = new ArrayInput(array('command' => 'tdk:git', 'action' => 'template'));
$this->application->run($input);

return Command::SUCCESS;
}

public function showInformation(Event $event): int
{
$input = new ArrayInput(array('command' => 'tdk:help', 'type' => 'summary'));
$this->application->run($input);

$input = new ArrayInput(array('command' => 'tdk:help', 'type' => 'done'));
$this->application->run($input);

return Command::SUCCESS;
}
}

0 comments on commit 8d19922

Please sign in to comment.