Composer + Modman + n98magerun

First of all, a bit of history. At the dawn of development of Magento extensions, our team began using composer to install Magento extensions into the project, but we have encountered a challenge, that is while developing to keep the extension code separately from Magento core. The thing is that Magento 1.x has a rather complex structure and it forces you to mix up your own file extensions with thousands of files and directories of Magento core. For some time, we used to solve this problem through composer even though in general it wasn't suited for such tasks. I even asked our back-end colleagues how do they solve this problem and I got: "We do it in the old conventional way of copying all necessary files in the project". No, that's not our way to do it – looking for all relevant files when moving out the project into the composer. And what if we somehow missed or forgot the extension initialization file? So what do certified Magento developers use for extension development?

The Objective: To create an extension skeleton and implement it as a composer unit at the same time minimizing the time effort to do it.

We started with the idea to install the extension and symlinks through the composer but it took a lot of time and the composer update was slow, so later we abandoned this idea. We were in need of a tool to create symlinks next to the Magento Core directories, based on a certain mapping. And then we have learned about Modman, we tested and implemented this solution.

So what is Modman?

Modman is an extension manager that allows you to save the files of your Magento extensions separately from thousands of Magento Core files. What's more, you can store the extension files in a separate repository of version control system, it's a great additional feature.

Getting started

  1. Go to the Magento site directory and enter in console "modman init", this way a service directory is created where all .modman extensions will be installed in the future (by analogy with the composer – only here this function is performed by vendor directory)
  2. Be sure to allow the use of symlinks in Magento Admin Panel: System> Configuration> Advanced> Developer
  3. One of the options is to create a modman link path_to_module_folder (there is also a modman clone repo_url - specifies the path to the repository)
  4. To be able to create a modman link or a modman clone the extension should contain the mapping file. Mapping is specified for each extension file by following the source -> destination pattern.

One of the advantages is the full integration of modman and composer. Composer can read the mapping of a modman file which means the mapping can be stored in a single file, and you can use two technologies simultaneously.

Now the most interesting part – how to automate all the routine tasks? The answer lies in using two tools called n98magerun and generate-modman. Regarding n98magerun, there are written a lot of different articles so we won’t concentrate on it. Below you can find the reference to the tools:

https://github.com/netz98/n98-magerun

https://github.com/mhauri/generate-modman

How n98magerun and generate-modman can be applied to modman? N98magerun has an extension generator, but we should add the magic keys:


n98-magerun dev:module:create --add-all --modman --add-composer --author-name="Komplizirte Technologien" --author-email="support@kt-team.de" Komplizierte Generated local

The team will create the skeleton of Generated extension with a standard Magento extensions structure, ready to go composer.json configuration file with namespace Komplizierte in the local code pull and corresponding modman mapping file. Keys --author-name and --author-email will add necessary parameters to composer.json

The catalogue structure turned out to be a little unconventional due to the src directory. Let's remove it: transfer all the content of src directory to the current folder, delete src and call for automatic mapping generator – generate-modman. As a result you should get a following structure:

Let's say in the process we had to map one more directory – do not forget to regenerate the Modman mapping file and fix all symlinks with modman repair. From the documentation:


repair       rebuild all modman-created symlinks (no updates performed)

You can enter “modman” in the console and it will provide you with the necessary documentation in which you can quickly find the right key.

The tools are provided, the problem is solved. See you in the next post! ;-)

Translated by Vitaly Zubkov