Skip to content

Commit

Permalink
DQA-8675: Toolkit composer plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
joaocsilva committed Mar 19, 2024
1 parent 5b75c04 commit 0ae1762
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 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 = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Ignore files for distribution archives.
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
phpstan.neon export-ignore
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
/vendor/
/.idea/
/composer.lock
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# A Composer plugin for Toolkit

This plugin will print any existing notification from the QA Website API.
33 changes: 33 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "ec-europa/toolkit-composer-plugin",
"description": "A Composer plugin for Toolkit",
"type": "composer-plugin",
"license": "MIT",
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
"psr-4": {
"Toolkit\\ComposerPlugin\\": "src"
}
},
"require": {
"php": ">=8.1",
"composer-plugin-api": "^2.0"
},
"require-dev": {
"composer/composer": "^2.0",
"phpstan/extension-installer": "^1.3"
},
"extra": {
"class": "Toolkit\\ComposerPlugin\\Plugin"
},
"config": {
"allow-plugins": {
"phpstan/extension-installer": true
}
},
"scripts": {
"notifications": "Toolkit\\ComposerPlugin\\Plugin::runNotifications",
"test": "./vendor/bin/phpstan --configuration=phpstan.neon"
}
}
11 changes: 11 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
parameters:
level: 9
paths:
- src
excludePaths:
- vendor
ignoreErrors:
-
message: "#^Unsafe usage of new static\\(\\)\\.$#"
count: 1
path: src/Plugin.php
79 changes: 79 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

declare(strict_types=1);

namespace Toolkit\ComposerPlugin;

use Composer\Composer;
use Composer\EventDispatcher\EventSubscriberInterface;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;
use Composer\Script\Event;
use Composer\Script\ScriptEvents;
use Composer\Util\ProcessExecutor;

/**
* Toolkit composer plugin.
*/
class Plugin implements PluginInterface, EventSubscriberInterface
{

/**
* {@inheritdoc}
*/
public function activate(Composer $composer, IOInterface $io)
{
}

/**
* {@inheritdoc}
*/
public function deactivate(Composer $composer, IOInterface $io)
{
}

/**
* {@inheritdoc}
*/
public function uninstall(Composer $composer, IOInterface $io)
{
}

/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
return [
ScriptEvents::POST_INSTALL_CMD => 'notifications',
ScriptEvents::POST_UPDATE_CMD => 'notifications',
];
}

/**
* Print the Toolkit notifications.
*/
public function notifications(Event $event): void
{
$binDir = $event->getComposer()->getConfig()->get('bin-dir') ?: 'vendor/bin';
$runner = "$binDir/run";
if (!file_exists($runner)) {
return;
}
$output = '';
(new ProcessExecutor($event->getIO()))
->execute("$runner toolkit:notifications", $output);
if (!empty($output)) {
$event->getIO()->write($output);
}
}

/**
* Manually execute the notifications command.
*/
public static function runNotifications(Event $event): void
{
(new static())->notifications($event);
}

}

0 comments on commit 0ae1762

Please sign in to comment.