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

Implement CommandProvider instead of scripts

Remove subscribed events that are covered by other packages
Add test scripts to ahoy
parent 9bb14c24
No related branches found
No related tags found
No related merge requests found
ahoyapi: v2
commands:
phpcs:
cmd: phpcs --standard=DrupalPractice $(pwd)/web/modules/custom/ $(pwd)/web/profiles/custom/ $(pwd)/web/themes/custom/
usage: PHP coding standards
phpunit:test:
cmd: vendor/bin/phpunit --configuration $(pwd)/tests/phpunit.xml.dist
usage: PHP unit tests
phpunit:list:suites:
cmd: vendor/bin/phpunit --configuration $(pwd)/tests/phpunit.xml.dist --list-suites
usage: List available test suites of PHP unit tests
phpunit:list:groups:
cmd: vendor/bin/phpunit --configuration $(pwd)/tests/phpunit.xml.dist --list-groups
usage: List available test groups of PHP unit tests
ahoyapi: v2
commands:
exec:
cmd: docker run -it -v /var/run/docker.sock:/var/run/docker.sock -v ${PWD}:/drupal -v $SSH_AUTH_SOCK:/ssh-agent -v ${HOME}/.traefik:/root/.traefik -e SSH_AUTH_SOCK=/ssh-agent -w /drupal registry.lakedrops.com/docker/gitlab-drupal-ci "$@"
hide: true
up:
cmd: docker run -it -v /var/run/docker.sock:/var/run/docker.sock -v ${PWD}:/drupal -v $SSH_AUTH_SOCK:/ssh-agent -v ${HOME}/.traefik:/root/.traefik -e SSH_AUTH_SOCK=/ssh-agent -w /drupal registry.lakedrops.com/docker/gitlab-drupal-ci /usr/bin/fish
cmd: ahoy dev exec /usr/bin/fish
usage: Start container with all development tools
update:
cmd: docker pull registry.lakedrops.com/docker/gitlab-drupal-ci
usage: Update image with the latest development tools
scaffold:
cmd: ahoy dev exec composer lakedrops:scaffold
usage: (Re-)Configure this project for developers
......@@ -36,7 +36,7 @@
"drupal/coder": "^8.2",
"lakedrops/ahoy": "^1.0.0",
"lakedrops/behat4drupal": "^1.0.0",
"lakedrops/composer-json-utils": "^1.2.0",
"lakedrops/composer-json-utils": "^1.3.0",
"lakedrops/composer-scripts": "^1.1.0",
"lakedrops/docker4drupal": "^1.0.0",
"lakedrops/dorgflow": "^1.0.0",
......@@ -60,27 +60,18 @@
}
},
"extra": {
"temp": {
},
"class": "LakeDrops\\Drupal8ScaffoldDeveloper\\Plugin",
"lakedrops": {
"scripts": {
"lakedrops": {
"callback": "LakeDrops\\Drupal8ScaffoldDeveloper\\Plugin::scaffold",
"description": "(Re-)Configure this project for developers."
}
},
"ahoy": {
"dev": {
"usage": "Development tools for Drupal",
"imports": ["ahoy.yml"]
},
"test": {
"usage": "Test tools",
"imports": ["ahoy.test.yml"]
}
}
}
},
"scripts": {
"install-codestandards": ["Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run"],
"post-install-cmd": ["@install-codestandards"],
"post-update-cmd": ["@install-codestandards"]
}
}
<?php
namespace LakeDrops\Drupal8ScaffoldDeveloper;
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 ScaffoldCommand(),
];
}
}
......@@ -2,9 +2,6 @@
namespace LakeDrops\Drupal8ScaffoldDeveloper;
use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Script\Event;
use LakeDrops\Component\Composer\BaseHandler;
use LakeDrops\Component\Dotenv\Dotenv;
use LakeDrops\Docker4Drupal\Handler as D4D;
......@@ -20,17 +17,15 @@ class Handler extends BaseHandler {
/**
* Post project create event to execute the scaffolding.
*
* @param \Composer\Script\Event $event
* The event that triggered the plugin.
*
* @throws \Twig_Error_Loader
* @throws \Twig_Error_Runtime
* @throws \Twig_Error_Syntax
* @throws \Exception
*/
public function setupLakeDropsProject(Event $event) {
public function setupLakeDropsProject() {
// We only do the fancy stuff for developers.
if (!$event->isDevMode()) {
if (!$this->isDevMode()) {
return;
}
......@@ -39,6 +34,7 @@ class Handler extends BaseHandler {
$installationManager = $this->composer->getInstallationManager();
$drupalCorePackage = $this->getDrupalCorePackage();
/** @noinspection NullPointerExceptionInspection */
$corePath = $installationManager->getInstallPath($drupalCorePackage);
// Directory where the root project is being created.
......@@ -161,8 +157,8 @@ class Handler extends BaseHandler {
// If available, also configure Docker4Drupal.
if ($this->getPackage('lakedrops/docker4drupal')) {
$handler = new D4D($event->getComposer(), $event->getIO());
$handler->configureProject($event);
$handler = new D4D($this->composer, $this->io);
$handler->configureProject();
}
}
......@@ -172,7 +168,7 @@ class Handler extends BaseHandler {
* @return array
* The settings from the extra configuration.
*/
protected function getOptions() {
protected function getOptions(): array {
$extra = $this->composer->getPackage()->getExtra() + ['d8-project-scaffold' => []];
$options = $extra['d8-project-scaffold'] + [
'chg-acl' => FALSE,
......
......@@ -39,38 +39,23 @@ class Plugin extends BasePlugin {
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
ScriptEvents::POST_CREATE_PROJECT_CMD => 'postCreateProject',
ScriptEvents::POST_UPDATE_CMD => 'postUpdate',
];
public function getCapabilities(): array {
return array(
\Composer\Plugin\Capability\CommandProvider::class => CommandProvider::class,
);
}
/**
* Post create project event callback.
*
* @param \Composer\Script\Event $event
* The event that triggered the plugin.
*/
public function postCreateProject(Event $event) {
$this->scaffoldHandler->downloadScaffold();
$this->scaffoldHandler->generateAutoload();
$this->handler->setupLakeDropsProject($event);
}
/**
* Post update event callback.
*
* @param \Composer\Script\Event $event
* The event that triggered the plugin.
* {@inheritdoc}
*/
public function postUpdate(Event $event) {
$this->scaffoldHandler->downloadScaffold();
$this->scaffoldHandler->generateAutoload();
public static function getSubscribedEvents(): array {
return [
ScriptEvents::POST_CREATE_PROJECT_CMD => 'postCreateProject',
];
}
/**
* Callback to setup the project.
* Post create project event callback.
*
* @param \Composer\Script\Event $event
* The event that triggered the plugin.
......@@ -79,9 +64,12 @@ class Plugin extends BasePlugin {
* @throws \Twig_Error_Runtime
* @throws \Twig_Error_Syntax
*/
public static function scaffold(Event $event) {
$handler = new Handler($event->getComposer(), $event->getIO());
$handler->setupLakeDropsProject($event);
public function postCreateProject(Event $event) {
/** @var Handler $handler */
$handler = $this->handler;
$handler
->setEvent($event)
->setupLakeDropsProject();
}
}
<?php
namespace LakeDrops\Drupal8ScaffoldDeveloper;
use LakeDrops\Component\Composer\BaseCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class ScaffoldCommand extends BaseCommand {
/**
* {@inheritdoc}
*/
protected function configure() {
$this->setName('lakedrops:scaffold');
$this->setDescription('(Re-)Configure this project for developers.');
}
/**
* {@inheritdoc}
*/
public function getHandlerClass() {
return Handler::class;
}
/**
* {@inheritdoc}
*
* @throws \Twig_Error_Loader
* @throws \Twig_Error_Runtime
* @throws \Twig_Error_Syntax
*/
protected function execute(InputInterface $input, OutputInterface $output) {
parent::execute($input, $output);
/** @var Handler $handler */
$handler = $this->handler;
$handler->setupLakeDropsProject();
}
}
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