Using Composer For Pantheon Quicksilver Scripts

Composer is rapidly becoming (or some could argue has become) the de-facto way to manage Drupal sites.  Drupal has implemented a Composer facade to facilitate inclusion of modules and themes via Composer, there are numerous guides out there outlining how to use Composer with it, and statements have been made along the lines of "if you aren't using Composer to build Drupal sites, you are doing it wrong".  This is all fine and good, but in order to fully adopt Composer for Drupal builds we need to be able to use Composer to manage all aspects of our project.

One item of particular importance for the work I do with Mindgrub revolves around integration with our hosting solutions.  In particular, we use Pantheon with a lot of our hosting and so any offerings that Pantheon provides also needs to work with Composer.  Pantheon offers a system called Quicksilver which allows us to run certain operations when certain actions happen.  For example, we frequently ship Quicksilver scripts with our projects to revert Features every time we push code to the dev environment and deploy code as well as sanitize the database when we pull the production database back to our testing environment.  These scripts would be manually added to each of our projects or become part of our starter kit where they would never receive the latest updates.

During Florida Drupal Camp 2017, I announced Quicksilver Composer Scripts, a way for being able to include Quicksilver scripts in your projects via Composer. Previously, trying to include Quicksilver scripts via Composer would place them in the vendor directory with no way to move them into Pantheon's private directory.  With Quicksilver Composer Scripts, you can now specify an install location for your Composer scripts of the quicksilver-script.  The installer ships with a reasonable set of defaults (it puts your Quicksilver scripts at we/private/scripts/quicksilver/{script-name}) but you can also customize the install path if you would like them located elsewhere.  Simply require your Quicksilver script in your composer.json file and, if the script doesn't include Quicksilver Composer Scripts, require Quicksilver Composer Scripts.

Here's an example composer.json file:

{
  "name": "rvtraveller/qs-composer-installer-example",
  "type": "project",
  "license": "GPL-2.0+",
  "repositories": [
    {
      "type": "composer",
      "url": "https://packages.drupal.org/8"
    }
  ],
    "require": {
    "composer/installers": "^1.0.20",
    "rvtraveller/qs-composer-installer": "^1.1",
    "drupal-composer/drupal-scaffold": "^2.0.1",
    "cweagans/composer-patches": "^1.0",

    "drupal/core": "~8",

    "drupal/console": "^1.0.0-rc8",
    "drush/drush": "~8",
    "drupal/config_direct_save": "^1.0"
  },
  "require-dev": {
    "mikey179/vfsstream": "^1.2",
    "behat/behat": "3.*",
    "behat/mink": "^1.7",
    "behat/mink-extension": "^2.2",
    "behat/mink-goutte-driver": "^1.2",
    "jcalderonzumba/gastonjs": "^1.0.2",
    "jcalderonzumba/mink-phantomjs-driver": "^0.3.1",
    "drupal/drupal-extension": "^3.1",
    "drush-ops/behat-drush-endpoint": "^0.0.4",
    "pantheon-systems/quicksilver-pushback": "~1",
    "phpunit/phpunit": "^4.8",
    "symfony/css-selector": "^2.8"
  },
  "conflict": {
      "drupal/drupal": "*"
  },
  "minimum-stability": "alpha",
  "prefer-stable": true,
  "autoload": {
    "classmap": [
      "scripts/composer/ScriptHandler.php"
    ]
  },
  "extra": {
    "installer-paths": {
      "web/core": ["type:drupal-core"],
      "web/modules/contrib/{$name}": ["type:drupal-module"],
      "web/profiles/contrib/{$name}": ["type:drupal-profile"],
      "web/themes/contrib/{$name}": ["type:drupal-theme"],
      "drush/contrib/{$name}": ["type:drupal-drush"]
    }
  }
}

Currently, there are a few Quicksilver scripts that have been ported to this new format:

If you encounter any issues, the Github Issue Queue is ready and waiting (and Pull Requests are always most welcome).  Happy Coding!

 

Add new comment