Stop making, start composing - Using Composer for Drupal development

32
Stop making, start composing! Using Composer for Drupal development

description

Walkthrough of how Composer can be used to manage Drupal projects.

Transcript of Stop making, start composing - Using Composer for Drupal development

Page 1: Stop making, start composing - Using Composer for Drupal development

Stop making,start composing!

Using Composer for Drupal development

Page 2: Stop making, start composing - Using Composer for Drupal development

• CTO and partner at Reload! A/S

• Ding.Core team member

• Maintainer of wsdl2phpgenerator

• Interested in developer workflows automation and code quality.

[email protected] / @kasperg

About me

Page 3: Stop making, start composing - Using Composer for Drupal development

• Drupal development agency

• 15 people

• Office in Frederiksberg

• Specialists in agile development, complex solutions, integrations and consultancy

• Clients include Danish Radio, IDA, Samvirke, STOFA, TV2 and others

Page 4: Stop making, start composing - Using Composer for Drupal development
Page 5: Stop making, start composing - Using Composer for Drupal development

What is wrong about Drush Make?

• Making is slow

• Making is frail

• Drush Make is not intended for rebuilding

Page 6: Stop making, start composing - Using Composer for Drupal development
Page 7: Stop making, start composing - Using Composer for Drupal development

Get off the island […] get involved in the wider PHP community, both to learn

from it and to share with it.

– Larry Garfield, Drupal Core contribuor, 31 December 2012

!

!

!

Page 8: Stop making, start composing - Using Composer for Drupal development

What is right about Drush Make

• Overview of used

projects

• Supports patching

• Support for non-Drupal

code

projects[feedback_simple][subdir] = contrib projects[feedback_simple][version] = 1.6 !projects[feeds][subdir] = contrib projects[feeds][version] = 2.0-alpha7 ; Support the use of summary on body fields. Summary here ; is the built-in teaser in Drupal. projects[feeds][patch][962912] = http://drupal.org/files/node-summary-mapper-962912-11.patch !libraries[chosen][download][type] = git libraries[chosen][download][url] = https://github.com/harvesthq/chosen.git libraries[chosen][download][revision] = v0.9.9

Page 9: Stop making, start composing - Using Composer for Drupal development
Page 10: Stop making, start composing - Using Composer for Drupal development

5 minute Composer crash course

Page 11: Stop making, start composing - Using Composer for Drupal development

What is Composer?Composer is a project dependency manager,

not a package manager.

!

Inspired by Ruby Bundler and Node.JS npm

!

Cross-platform compatible (Windows, Linux, and OSX)

Requires >= PHP 5.3.2 and

optionally Subversion, GIT, and/or Mercurial

!

Released in 2011 under the MIT license

Developed by: Nils Adermann and Jordi Boggiano

Page 12: Stop making, start composing - Using Composer for Drupal development

What does Composer do?

• Manages dependent

libraries

• Handles cascading

dependencies

• Declarative dependency

• Install and update

dependencies

• Autoload dependencies

{ "name": "kasperg/composer-demo", "description": "A demo Composer project", "require": { "silex/silex": "1.1.*" }, "authors": [ { "name": "Kasper Garnaes", "email": "[email protected]" } ] }

Page 13: Stop making, start composing - Using Composer for Drupal development

Live demo

Page 14: Stop making, start composing - Using Composer for Drupal development

Packagist

• Over 40.000 packages

• Default package repository for Composer

• Contains nearly every widely used open source PHP package

• Free accounts to register and maintain own packages

Page 15: Stop making, start composing - Using Composer for Drupal development

Composer vs. Drush Make

• Manages dependent

libraries

• Handles cascading

dependencies

• Declarative dependency

# composer.json { "require": { "silex/silex": "1.1.*" }, } !!!# drush.make api = 2 core = 7.x projects[ctools][version] = 1.4

Page 16: Stop making, start composing - Using Composer for Drupal development

By Carsten ten Brink, https://flic.kr/p/fX4XWL

Time to jump through some hoops

Page 17: Stop making, start composing - Using Composer for Drupal development
Page 18: Stop making, start composing - Using Composer for Drupal development

Lets get started!

Page 19: Stop making, start composing - Using Composer for Drupal development

Drupal Core

• Located in the root directory of the project

• Use Composer custom installers

• Example: Composer non-destructive archive installer

• https://github.com/azt3k/non-destructive-archive-installer

Page 20: Stop making, start composing - Using Composer for Drupal development

Modules and themes I

• Composer repository for Drupal projects

• Developed by Will MiltonLead technology architect, Promet Source

• http://static.drupal-packagist.org/v0.2.0/

• Source: https://github.com/winmillwill/drupal-parse-composer

Page 21: Stop making, start composing - Using Composer for Drupal development

Modules and themes II

• Package naming:drupal/[project-name]

• Version naming:[drupal-major-version]. [project-major-version]. [project-minor-version]

• http://static.drupal-packagist.org/v0.2.0/

• Source: https://github.com/winmillwill/drupal-parse-composer

Page 22: Stop making, start composing - Using Composer for Drupal development

Modules and themes III

• Move projects to the appropriate location using Composer Installers

• http://composer.github.io/installers/

• Supports individual projects and types including drupal-module, drupal-theme, drupal-profile, drupal-drush

Page 23: Stop making, start composing - Using Composer for Drupal development

Patches

• Composer does not support patching projects. It promotes a fork/pullrequest-based workflow.

• Use Composer Patches Plugin

• Developed for TYPO3

• https://github.com/netresearch/composer-patches-plugin

Page 24: Stop making, start composing - Using Composer for Drupal development

Libraries

• Packagist packages can be added through requires

• Includes PHP but also JS, CSS!

• Packages without composer support can be defined manually through composer.json

• Same approach applies for sandboxes

Page 25: Stop making, start composing - Using Composer for Drupal development

• Composer can support the same use cases as Drush Make in the development process and more through community work.

• Enables tapping into and sharing with the PHP community at large.

Wrap up

By Richard Paterson, https://flic.kr/p/6wnBHM

Page 26: Stop making, start composing - Using Composer for Drupal development

Project template

• Use a project template to get started and avoid repeating boilerplate configuration

• php composer.phar create-project reload/drupal-composer-project some-dir --stability dev —no-interaction

• https://github.com/reload/drupal-composer-project

Page 27: Stop making, start composing - Using Composer for Drupal development

Whats next?

Page 28: Stop making, start composing - Using Composer for Drupal development

Drupal composer repository

• drupal.org must provide an authoritative Composer repository for Drupal packages.

• Could replace updates.drupal.org over time.

• Until then: Continued work on static.drupal-packagist.org.

Page 29: Stop making, start composing - Using Composer for Drupal development

!

The Future of Drush

• Relevant as ever

• Reduced scope

• make and dl no longer

needed

Page 30: Stop making, start composing - Using Composer for Drupal development

What about Drupal 8?

• Already has a composer.json file

in the project root.

• Better directory structure makes things a lot easier.

• Drupal 8 core directory subslit can be used as a Composer package

• https://github.com/tstoeckler/drupal-core

Page 31: Stop making, start composing - Using Composer for Drupal development

Suomisvej 2, 2. sal 1927 Frederiksberg

reload.dk

[email protected]

!

Page 32: Stop making, start composing - Using Composer for Drupal development

!

!

https://github.com/reload/job-application

[email protected]

!

ALWAYS LOOKING FOR TALENTED DEVELOPERS