Skip to content
Snippets Groups Projects
Commit 8513b736 authored by jurgenhaas's avatar jurgenhaas
Browse files

Move scripts to command provider

parent ac0a579e
No related branches found
No related tags found
No related merge requests found
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
}, },
"require": { "require": {
"composer-plugin-api": "^1.0.0", "composer-plugin-api": "^1.0.0",
"lakedrops/composer-json-utils": "^1.0.0" "lakedrops/composer-json-utils": "^1.3.0"
}, },
"require-dev": { "require-dev": {
"composer/composer": "^1.5.0", "composer/composer": "^1.5.0",
...@@ -47,12 +47,6 @@ ...@@ -47,12 +47,6 @@
"extra": { "extra": {
"class": "LakeDrops\\Ahoy\\Plugin", "class": "LakeDrops\\Ahoy\\Plugin",
"lakedrops": { "lakedrops": {
"scripts": {
"ahoy": {
"callback": "LakeDrops\\Ahoy\\Plugin::scripts",
"description": "Scan LakeDrops plugins for ahoy scripts."
}
},
"ahoy": { "ahoy": {
"me": { "me": {
"usage": "Ahoy plugin commands", "usage": "Ahoy plugin commands",
......
<?php
namespace LakeDrops\Ahoy;
use Composer\Plugin\Capability\CommandProvider as CommandProviderCapability;
use Composer\Command\BaseCommand;
class CommandProvider implements CommandProviderCapability {
/**
* Retrieves an array of commands
*
* @return BaseCommand[]
*/
public function getCommands(): array {
return [
new UpdateCommand(),
];
}
}
...@@ -2,9 +2,7 @@ ...@@ -2,9 +2,7 @@
namespace LakeDrops\Ahoy; namespace LakeDrops\Ahoy;
use Composer\Composer; use LakeDrops\Component\Composer\BaseHandler;
use Composer\IO\IOInterface;
use Composer\Script\Event;
use LakeDrops\Component\Composer\Utils; use LakeDrops\Component\Composer\Utils;
use Symfony\Component\Yaml\Yaml; use Symfony\Component\Yaml\Yaml;
...@@ -13,58 +11,15 @@ use Symfony\Component\Yaml\Yaml; ...@@ -13,58 +11,15 @@ use Symfony\Component\Yaml\Yaml;
* *
* @package LakeDrops\Drupal8Scaffold * @package LakeDrops\Drupal8Scaffold
*/ */
class Handler { class Handler extends BaseHandler {
/**
* The composer object running this session.
*
* @var \Composer\Composer
*/
protected $composer;
/**
* The input-output object for the composer session.
*
* @var \Composer\IO\IOInterface
*/
protected $io;
/**
* Handler constructor.
*
* @param \Composer\Composer $composer
* The composer object.
* @param \Composer\IO\IOInterface $io
* The input-output object.
*/
public function __construct(Composer $composer, IOInterface $io) {
$this->composer = $composer;
$this->io = $io;
}
/**
* Retrieve a package from the current composer process.
*
* @param string $name
* Name of the package to get from the current composer installation.
*
* @return \Composer\Package\PackageInterface
* The package.
*/
protected function getPackage($name) {
return $this->composer->getRepositoryManager()->getLocalRepository()->findPackage($name, '*');
}
/** /**
* Update ahoy scripts of all LakeDrops plugins. * Update ahoy scripts of all LakeDrops plugins.
*
* @param \Composer\Script\Event $event
* The event that triggered the plugin.
*/ */
public function updateScripts(Event $event) { public function updateScripts() {
// We only do the fancy stuff for developers. // We only do the fancy stuff for developers.
if (!$event->isDevMode()) { if (!$this->isDevMode()) {
return; return;
} }
...@@ -94,14 +49,4 @@ class Handler { ...@@ -94,14 +49,4 @@ class Handler {
$this->git('ignore ' . '.ahoy.yml'); $this->git('ignore ' . '.ahoy.yml');
} }
/**
* Wrapper for git command in the root directory.
*
* @param string $command
* Git command name, arguments and/or options.
*/
protected function git($command) {
passthru(escapeshellcmd('git -c "user.email=d8-project@lakedrops.com" ' . $command));
}
} }
...@@ -2,30 +2,29 @@ ...@@ -2,30 +2,29 @@
namespace LakeDrops\Ahoy; namespace LakeDrops\Ahoy;
use Composer\Composer;
use Composer\EventDispatcher\EventSubscriberInterface;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;
use Composer\Script\Event; use Composer\Script\Event;
use Composer\Script\ScriptEvents; use Composer\Script\ScriptEvents;
use LakeDrops\Component\Composer\BasePlugin;
/** /**
* Composer plugin for handling Ahoy scripts. * Composer plugin for handling Ahoy scripts.
*/ */
class Plugin implements PluginInterface, EventSubscriberInterface { class Plugin extends BasePlugin {
/** /**
* The handler object for events. * {@inheritdoc}
*
* @var \LakeDrops\ComposerScripts\Handler
*/ */
protected $handler; public function getHandlerClass() {
return Handler::class;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function activate(Composer $composer, IOInterface $io) { public function getCapabilities(): array {
$this->handler = new Handler($composer, $io); return array(
\Composer\Plugin\Capability\CommandProvider::class => CommandProvider::class,
);
} }
/** /**
...@@ -46,18 +45,11 @@ class Plugin implements PluginInterface, EventSubscriberInterface { ...@@ -46,18 +45,11 @@ class Plugin implements PluginInterface, EventSubscriberInterface {
* The event that triggered the plugin. * The event that triggered the plugin.
*/ */
public function updateScripts(Event $event) { public function updateScripts(Event $event) {
$this->handler->updateScripts($event); /** @var Handler $handler */
} $handler = $this->handler;
$handler
/** ->setEvent($event)
* Callback to scan plugins for ahoy scripts. ->updateScripts();
*
* @param \Composer\Script\Event $event
* The event that triggered the plugin.
*/
public static function scripts(Event $event) {
$handler = new Handler($event->getComposer(), $event->getIO());
$handler->updateScripts($event);
} }
} }
<?php
namespace LakeDrops\Ahoy;
use LakeDrops\Component\Composer\BaseCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class UpdateCommand extends BaseCommand {
/**
* {@inheritdoc}
*/
protected function configure() {
$this->setName('lakedrops:ahoy');
$this->setDescription('Scan LakeDrops plugins for ahoy scripts.');
}
/**
* {@inheritdoc}
*/
public function getHandlerClass() {
return Handler::class;
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output) {
parent::execute($input, $output);
/** @var Handler $handler */
$handler = $this->handler;
$handler->updateScripts();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment