From f8e99b7ca6c2c21e513d45a47b10533be298d6b9 Mon Sep 17 00:00:00 2001
From: jurgenhaas <juergen@paragon-es.de>
Date: Mon, 8 Jan 2018 15:50:12 +0100
Subject: [PATCH] #14 Move script collection into its own plugin

---
 CONTRIBUTING.md |  2 +-
 composer.json   |  6 +-----
 src/Handler.php | 32 --------------------------------
 src/Plugin.php  | 23 -----------------------
 4 files changed, 2 insertions(+), 61 deletions(-)

diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 425525a..5f9edfe 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -3,5 +3,5 @@
 It is important to use the following command for updates:
 
 ```bash
-copmoser update --no-plugins
+composer update --no-plugins
 ```
diff --git a/composer.json b/composer.json
index 390ff67..30f25a3 100644
--- a/composer.json
+++ b/composer.json
@@ -55,7 +55,7 @@
         "drupal/security_review": "1.x-dev",
         "drupal/stage_file_proxy": "^1.0-alpha3",
         "drush/drush": "9.0-beta4",
-        "lakedrops/composer-json-utils": "^0.1",
+        "lakedrops/composer-scripts": "^0.1",
         "lakedrops/docker4drupal": "^0.8",
         "lakedrops/dorgflow": "^0.3"
     },
@@ -77,10 +77,6 @@
                 "lakedrops-scaffold": {
                     "callback": "LakeDrops\\Drupal8Scaffold\\Plugin::scaffold",
                     "description": "(Re-)Configure docker for this project."
-                },
-                "lakedrops-scripts": {
-                    "callback": "LakeDrops\\Drupal8Scaffold\\Plugin::scripts",
-                    "description": "(Scan LakeDrops plugins for scripts."
                 }
             }
         }
diff --git a/src/Handler.php b/src/Handler.php
index b1198de..9a62b33 100644
--- a/src/Handler.php
+++ b/src/Handler.php
@@ -5,7 +5,6 @@ namespace LakeDrops\Drupal8Scaffold;
 use Composer\Composer;
 use Composer\IO\IOInterface;
 use Composer\Script\Event;
-use LakeDrops\Component\Composer\Utils;
 use LakeDrops\Docker4Drupal\Handler as D4D;
 use Symfony\Component\Filesystem\Filesystem;
 
@@ -214,37 +213,6 @@ class Handler {
     }
   }
 
-  /**
-   * 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();
-  }
-
   /**
    * Retrieve configuration for this package.
    *
diff --git a/src/Plugin.php b/src/Plugin.php
index 215152c..5b13226 100644
--- a/src/Plugin.php
+++ b/src/Plugin.php
@@ -34,8 +34,6 @@ class Plugin implements PluginInterface, EventSubscriberInterface {
   public static function getSubscribedEvents() {
     return array(
       ScriptEvents::POST_CREATE_PROJECT_CMD => 'postCreateProject',
-      ScriptEvents::POST_INSTALL_CMD => 'updateScripts',
-      ScriptEvents::POST_UPDATE_CMD => 'updateScripts',
     );
   }
 
@@ -49,16 +47,6 @@ class Plugin implements PluginInterface, EventSubscriberInterface {
     $this->handler->setupLakeDropsProject($event);
   }
 
-  /**
-   * 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 setup the project.
    *
@@ -70,15 +58,4 @@ class Plugin implements PluginInterface, EventSubscriberInterface {
     $handler->setupLakeDropsProject($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);
-  }
-
 }
-- 
GitLab