Skip to content
Snippets Groups Projects
Commit 043d744e authored by jurgenhaas's avatar jurgenhaas
Browse files

docker4drupal#24 Initial version of the ahoy plugin

parents
No related branches found
Tags v1.0.0
No related merge requests found
Pipeline #5315 canceled
# Drupal editor configuration normalization
# @see http://editorconfig.org/
# This is the top-most .editorconfig file; do not search in parent directories.
root = true
# All files.
[*]
end_of_line = LF
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[{composer.json,composer.lock}]
indent_size = 4
vendor
composer.lock
Deploy:
script:
- curl -XPOST -H'content-type:application/json' "https://packagist.org/api/update-package?username=${PACKAGIST_USERNAME}&apiToken=${PACKAGIST_API_TOKEN}" -d'{"repository":{"url":"'${CI_PROJECT_URL}'"}}'
{
"name": "lakedrops/ahoy",
"description": "This plugin collects available ahoy scripts from installed LakeDrops plugins and configures ahy in the project root.",
"type": "composer-plugin",
"keywords": [
"Ahoy",
"Drupal",
"Development",
"Install",
"Update"
],
"homepage": "https://gitlab.lakedrops.com/composer/plugin/ahoy",
"license": "GPL-2.0+",
"authors": [
{
"name": "Jürgen Haas",
"email": "juergen@paragon-es.de",
"homepage": "https://www.paragon-es.de",
"role": "Drupal Expert"
},
{
"name": "Richard Papp",
"email": "richard.papp@boromino.com",
"homepage": "http://www.boromino.com",
"role": "Drupal Expert"
}
],
"support": {
"issues": "https://gitlab.lakedrops.com/composer/plugin/ahoy/issues",
"source": "https://gitlab.lakedrops.com/composer/plugin/ahoy/tree/master"
},
"require": {
"composer-plugin-api": "^1.0.0",
"lakedrops/composer-json-utils": "^0.1"
},
"require-dev": {
"composer/composer": "^1.5.0",
"phpunit/phpunit": "^4.8.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
"psr-4": {
"LakeDrops\\Ahoy\\": "src/"
}
},
"extra": {
"class": "LakeDrops\\Ahoy\\Plugin",
"lakedrops": {
"scripts": {
"lakedrops-ahoy": {
"callback": "LakeDrops\\Ahoy\\Plugin::scripts",
"description": "Scan LakeDrops plugins for ahoy scripts."
}
}
}
}
}
<?php
namespace LakeDrops\Ahoy;
use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Script\Event;
use LakeDrops\Component\Composer\Utils;
use Symfony\Component\Yaml\Yaml;
/**
* Class Handler.
*
* @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, '*');
}
/**
* Update ahoy scripts of all LakeDrops plugins.
*
* @param \Composer\Script\Event $event
* The event that triggered the plugin.
*/
public function updateScripts(Event $event) {
// We only do the fancy stuff for developers.
if (!$event->isDevMode()) {
return;
}
$ahoy = [
'ahoyapi' => 'v2',
'commands' => [],
];
$installationManager = $this->composer->getInstallationManager();
foreach ($this->composer->getRepositoryManager()->getLocalRepository()->search('lakedrops/*') as $pkg) {
$pluginRoot = $installationManager->getInstallPath($this->getPackage($pkg['name']));
$pluginSettings = new Utils($this->composer, $pluginRoot);
foreach ($pluginSettings->getSubSubSection('extra', 'lakedrops', 'ahoy') as $command => $commands) {
$ahoy['commands'][$command] = [];
foreach ($commands['imports'] as $key => $import) {
$ahoy['commands'][$command]['imports'][$key] = './vendor/lakedrops/' . $pkg['name'] . '/' . $import;
}
}
}
$file = getcwd() . '/.ahoy.yml';
file_put_contents($file, $rendered = Yaml::dump($ahoy, 9, 2));
}
}
<?php
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;
/**
* Composer plugin for handling Ahoy scripts.
*/
class Plugin implements PluginInterface, EventSubscriberInterface {
/**
* The handler object for events.
*
* @var \LakeDrops\ComposerScripts\Handler
*/
protected $handler;
/**
* {@inheritdoc}
*/
public function activate(Composer $composer, IOInterface $io) {
$this->handler = new Handler($composer, $io);
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return array(
ScriptEvents::POST_CREATE_PROJECT_CMD => 'updateScripts',
ScriptEvents::POST_INSTALL_CMD => 'updateScripts',
ScriptEvents::POST_UPDATE_CMD => 'updateScripts',
);
}
/**
* Update ahoy scripts of all LakeDrops plugins.
*
* @param \Composer\Script\Event $event
* 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);
}
}
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