diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..89e9e06 --- /dev/null +++ b/.editorconfig @@ -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 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..d882dad --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +# Ignore files for distribution archives. +.editorconfig export-ignore +.gitattributes export-ignore +.gitignore export-ignore +phpstan.neon export-ignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..36a5d1e --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.DS_Store +/vendor/ +/.idea/ +/composer.lock diff --git a/README.md b/README.md new file mode 100644 index 0000000..4f8c184 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# A Composer plugin for Toolkit + +This plugin will print any existing notification from the QA Website API. diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..9b84806 --- /dev/null +++ b/composer.json @@ -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" + } +} diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..67c22e4 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,11 @@ +parameters: + level: 9 + paths: + - src + excludePaths: + - vendor + ignoreErrors: + - + message: "#^Unsafe usage of new static\\(\\)\\.$#" + count: 1 + path: src/Plugin.php diff --git a/src/Plugin.php b/src/Plugin.php new file mode 100644 index 0000000..346ac93 --- /dev/null +++ b/src/Plugin.php @@ -0,0 +1,79 @@ + '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); + } + +}