Some Fun with Drupal and Composer

At work, there has been lots of work making our code repos smaller for the fact that we would love our code reviews to only contain that in which we maintain. This means, all 3rd party code shouldn't be stored in our git repositories, and the changes that matter will not go unnoticed. To that end, Will Milton has went through some pretty pain staking development to get existing drupal modules into a packagist. This works with all versions of Drupal, as it's essentially, just Composer!

Now I know what most of yall are thinking... promoting your buddy because you work with him... Yeah well duh! Also, I think that some of his compelling arguments to my "specializing in Drupal" are well... compelling. I once was a general PHP developer and I see how Drupal typically has us doing "Drupal workflows." You see it everywhere... Hell there is Drupal modules that wrap PHP libraries, so that they behave "the Drupal way". Take Composer Manager for instance. Now... Hats off to those guys. They got the ball rollin, but I think Will has produced something much better and more of the "PHP way."

Now think of this. Right now, if I want to update core, I do a drush upc drupal -y and then do a git commit -a -m "Updating core to version 7.xx". I then do a pull request and send the change in for code review. Someone looks at this commit, and of course github goes... "This shit's too big, I can't show you a diff" and during the time my reviewer is cursing my name and has to do a manual diff on the code to see if I've snuck anything in there I shouldn't have. Even worse yet... they just merge it because they are like... it's just a core update.

wtf mate!

My sentiments? This should never happen in the first place. With composer this doesn't happen. Sure you have a git commit (most likely) moving the version up OR I change the composer.lock file because I did a composer update in my local.

Woah ho ho!! Look at that... I do a composer update and commit a composer.lock file... that's like... 6 lines in a file and my code review buddy is like "Hey dude... I love how you give me the easy commits."

Like you a lot bro

In the end, the only thing that sucks is that the very first time you build your site, you need the interwebz... provided the packages you need haven't been cached, but this is usually a requirement to be a web developer these days... am I right?

So get out there an use composer. Here... I even will give you a sample composer.json file and some links to some cool projects to take a look into (yes there is one problem with omega that has been reported. Work around by defining your own package.):

{
  "name": "generalredneck/poker-site",
  "license": "proprietary",
  "description": "Poker site",
  "minimum-stability": "stable",
  "authors": [
    {
      "name": "Allan Chappell",
      "email": "generalredneck@gmail.com"
    }
  ],
  "repositories": [
    {
      "type": "composer",
      "url": "http://static.drupal-packagist.org/v0.1.0/"
    },
    {
        "type": "package",
        "package": {
            "name": "pokermania/pokernetwork",
            "version": "4.6.48",
            "source": {
                "url": "https://github.com/pokermania/pokernetwork.git",
                "type": "git",
                "reference": "4.6.48"
            }
        }
    },
    {
        "type": "package",
        "package": {
            "name": "drupal/features_extra",
            "version": "7.1.0-beta1",
            "type": "drupal-module",
            "source": {
                "url": "http://git.drupal.org/project/features_extra.git",
                "type": "git",
                "reference": "7.x-1.0-beta1"
            }
        }
    }
  ],
  "require": {
    "composer/installers": "~1.0",
    "drupal/admin_menu": "~7.3.0-rc4",
    "drupal/ctools": "~7.1.4",
    "drupal/date": "~7.2.7",
    "drupal/drupal": "~7.28",
    "drupal/features": "~7.2.0",
    "drupal/features_extra": "~7.1.0-beta1",
    "drupal/globalredirect": "~7.1.5",
    "drupal/migrate": "~7.2.5",
    "drupal/module_filter": "~7.2.0-alpha2",
    "drupal/omega": "~7.4.2",
    "drupal/pathauto": "~7.1.2",
    "drupal/panels": "7.3.4",
    "drupal/strongarm": "~7.2.0",
    "drupal/token": "~7.1.5",
    "drupal/views": "~7.3.8",
    "guzzle/guzzle": "3.*",
    "pokermania/pokernetwork": "4.6.48",
    "winmillwill/settings_compile": "~2.0"
  },
  "require-dev": {
    "behat/mink-zombie-driver": "*",
    "behat/mink-extension": "~1.2",
    "behat/behat": "2.5.2",
    "drupal/devel": "~7.1.3",
    "drupal/devel_generate": "~7.1.3",
    "drupal/devel_node_access": "~7.1.3",
    "drupal/devel_themer": "7.1.*@dev",
    "drupal/diff": "~7.3.2",
    "drupal/mail_logger": "7.1.*@dev",
    "drupal/drupal-extension": "0.1.5",
    "phpunit/phpunit": "*"
  },
  "config": {
    "bin-dir": "bin"
  }
}

If you are looking to install files into the right directories in Drupal 7, take a look at Tangler.