Packagist server for Craft CMS 2 plugins, because why should Craft 2 miss out on all the Composer goodness?
-
Create a
composer.json
file in the root folder of your Craft 2 project. -
Add the following to your
composer.json
{ "repositories": [{ "type": "composer", "url": "https://craft2packages.miranj.in/" }] }
-
Use the standard
composer require <vendor>/<package>
command to add & install plugins that you wish to use with this project. You might have to specify a version constraint such as"1.*"
to ensure you don't install a newer, Craft 3 version of the plugin.composer require aelvan/imager-craft:"1.*"
Don’t see the plugin you want to use listed? Feel free to request inclusion, or better yet, add it yourself by submitting a pull request. Here's how:
-
First, make sure that the Craft 2 version of the plugin you wish to add isn't already available via Packagist. Some popular plugins (e.g. SEOmatic) have been Composer installable all this while, so there is no need to duplicate them here.
-
Add a new plugin inside
satis.yml
underrepositories:
with the following structure:aelvan/imager-craft: # <vendor>/<package-name> type: package package: - name: aelvan/imager-craft # <vendor>/<package-name> description: Image transforms. # Short description homepage: https://github.com/… # Plugin home page version: 1.6.4 # Latest Craft 2 supported version source: type: git reference: 1.6.4 # Git reference (usually a tag) url: https://github.com/… # Repository URL
-
Figure out the installation method. There are two broad types:
-
Plugins where the repository's root folder goes directly into
/craft/plugins/
. We can make use of Composer's nativecraft-plugin
installer for this variant. Add the following to thepackage
definition:type: craft-plugin require: composer/installers: "~1.0" extra: # optional installer-name: imager # needed if plugin folder name differs from package name
-
A subfolder inside the plugin repository needs to go into
/craft/plugins/
. We make use of a Composer plugin to copy the correct folder from thevendor
directory to/craft/plugins/
. Add the following to thepackage
definition:require: sasedev/composer-plugin-filecopier: "^1.1" extra: filescopier: source: vendor/aelvan/imager-craft/imager # vendor/<vendor>/<package>/<subfolder> destination: craft/plugins/imager # craft/plugins/<subfolder>
-
You will find plenty of examples already inside satis.yml
for the variants described above,
as well as for things like adding multiple versions of a plugin.
Refer to the official Composer repositories docs for all the supported options and variations.
- Derrick Grigg for inspiration and much of the hard work in creating a Composer workflow for Craft 2
- Pixel & Tonic for Craft CMS