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 @@
},
"require": {
"composer-plugin-api": "^1.0.0",
"lakedrops/composer-json-utils": "^1.0.0"
"lakedrops/composer-json-utils": "^1.3.0"
},
"require-dev": {
"composer/composer": "^1.5.0",
......@@ -47,12 +47,6 @@
"extra": {
"class": "LakeDrops\\Ahoy\\Plugin",
"lakedrops": {
"scripts": {
"ahoy": {
"callback": "LakeDrops\\Ahoy\\Plugin::scripts",
"description": "Scan LakeDrops plugins for ahoy scripts."
}
},
"ahoy": {
"me": {
"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 @@
namespace LakeDrops\Ahoy;
use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Script\Event;
use LakeDrops\Component\Composer\BaseHandler;
use LakeDrops\Component\Composer\Utils;
use Symfony\Component\Yaml\Yaml;
......@@ -13,58 +11,15 @@ use Symfony\Component\Yaml\Yaml;
*
* @package LakeDrops\Drupal8Scaffold
*/
class Handler {
/**
* 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, '*');
}
class Handler extends BaseHandler {
/**
* 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.
if (!$event->isDevMode()) {
if (!$this->isDevMode()) {
return;
}
......@@ -94,14 +49,4 @@ class Handler {
$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 @@
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\ScriptEvents;
use LakeDrops\Component\Composer\BasePlugin;
/**
* Composer plugin for handling Ahoy scripts.
*/
class Plugin implements PluginInterface, EventSubscriberInterface {
class Plugin extends BasePlugin {
/**
* The handler object for events.
*
* @var \LakeDrops\ComposerScripts\Handler
* {@inheritdoc}
*/
protected $handler;
public function getHandlerClass() {
return Handler::class;
}
/**
* {@inheritdoc}
*/
public function activate(Composer $composer, IOInterface $io) {
$this->handler = new Handler($composer, $io);
public function getCapabilities(): array {
return array(
\Composer\Plugin\Capability\CommandProvider::class => CommandProvider::class,
);
}
/**
......@@ -46,18 +45,11 @@ class Plugin implements PluginInterface, EventSubscriberInterface {
* The event that triggered the plugin.
*/
public function updateScripts(Event $event) {
$this->handler->updateScripts($event);
}
/**
* Callback to scan plugins for ahoy scripts.
*
* @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);
/** @var Handler $handler */
$handler = $this->handler;
$handler
->setEvent($event)
->updateScripts();
}
}
<?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