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

Get initial code from lakedrops/drupal-8-scaffold

parents
No related branches found
No related tags found
No related merge requests found
Pipeline #
# 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/composer-scripts",
"description": "This plugin collects available scripts from installed LakeDrops plugins and defines them in the composer.json file of the project root.",
"type": "composer-plugin",
"keywords": [
"Drupal",
"Development",
"Install",
"Update"
],
"homepage": "https://gitlab.lakedrops.com/composer/plugin/composer-scripts",
"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/composer-scripts/issues",
"source": "https://gitlab.lakedrops.com/composer/plugin/composer-scripts/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\\ComposerScripts\\": "src/"
}
},
"extra": {
"class": "LakeDrops\\ComposerScripts\\Plugin",
"lakedrops": {
"scripts": {
"lakedrops-composer-scripts": {
"callback": "LakeDrops\\ComposerScripts\\Plugin::scripts",
"description": "Scan LakeDrops plugins for scripts."
}
}
}
}
}
<?php
namespace LakeDrops\ComposerScripts;
use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Script\Event;
use LakeDrops\Component\Composer\Utils;
/**
* 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 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;
}
$settings = new Utils($this->composer);
$scripts = $settings->getSection('scripts');
$scriptDescriptions = $settings->getSubSection('extra', 'scripts-description');
$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', 'scripts') as $name => $script) {
$scripts[$name] = $script['callback'];
$scriptDescriptions[$name] = $script['description'];
}
}
$settings->setSection('scripts', $scripts);
$settings->setSubSection('extra', 'scripts-description', $scriptDescriptions);
$settings->write();
}
}
<?php
namespace LakeDrops\ComposerScripts;
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 drupal scaffold.
*/
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 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 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