Magento: Generate modman files

Tweet about this on TwitterShare on LinkedInShare on Google+Share on FacebookEmail this to someone

Last few weeks me and my team had to install around 10 third party Magento extensions. We have our own local setup and development workflow, but one of the key elements is MODMAN. All extensions (ours and the third party extensions) are linked in Magento by modman. With our current setup and the situation with the number of the new third party extensions we were forced to create modman files for all new extensions. We had to create manually the definitions in the modman files in order to define how the extensions files should be linked in Magento. There was no room for mistakes, but during the process we started experiencing problems, because of the human factor. From time to time we were missing to write modman definitions for some template, layout and css files.

I spotted the need that we need reliable and automated tool, which allows us to create modman files without missing any definitions. At the beginning I was thinking to write my own shell scrip, but as I didn’t want to reinvent the wheel I decided to use my professional network and to ask the Magento community (thanks to one of my first mentors Stefan Stefanov for always reminding me to search for existing concepts / tools / frameworks rather than reinventing the wheel). I asked for help in twitter. The first minute I published my tweet I got answers from Magento community members.

Modman generator question - tweet

The result: The community purposed 3 different working solutions and there is a promise for one more that will be wrapped in PHP Storm plugin. Below I am going to write summary about the solutions. My hope is that this may help to somebody, who is dealing with the same task as me.

  1. Suggested by @mhauri (my choice) – instructions and download from: https://github.com/mhauri/generate-modman

    Shell scrip that creates a modman file with optimal number of files. The script shows help message in case you pass incorrect arguments.

    It scans the folders usually used from the Magento developers to store their files:

    • app/code
    • app/etc
    • app/locale
    • app/design
    • js
    • lib
    • media
    • skin
    • shell
    • var

    * There is a possibility that the shell script may not handle the cases when the developer of the third party extension has decided to put files outside of the folders listed above. In this case you can type:

    generate-modman --include-others name-of-custom-folder
    

    For reference this is a snippet of file generated by generate-modman script:

    # Modman file generated by 'generate-modman' (https://github.com/mhauri/generate-modman)
    # app/code
    app/code/community/Unirgy/Dropship            app/code/community/Unirgy/Dropship
    # app/etc
    app/etc/modules/Unirgy_Dropship.xml            app/etc/modules/Unirgy_Dropship.xml
    # app/locale
    app/locale/en_US/template/email/udropship_password.html            app/locale/en_US/template/email/udropship_password.html
    app/locale/en_US/template/email/udropship_statement.html            app/locale/en_US/template/email/udropship_statement.html
    app/locale/en_US/template/email/udropship_vendor.html            app/locale/en_US/template/email/udropship_vendor.html
    app/locale/en_US/template/email/udropship_vendor_notify_lowstock.html            app/locale/en_US/template/email/udropship_vendor_notify_lowstock.html
    app/locale/en_US/template/email/udropship_vendor_shipment_comment.html            apmplate/email/udro pship_vendor_shipment_comment.html
    app/locale/en_US/Unirgy_Dropship.csv            app/locale/en_US/Unirgy_Dropship.csv
    # app/design
    app/design/adminhtml/default/default/layout/udropship.xml            app/design/adminhtml/default/default/layout/udropship.xml
    app/design/adminhtml/default/default/template/udropship/carriers.phtml            app/design/adminhtml/default/default/template/udropship/carriers.phtml
    app/design/adminhtml/default/default/template/udropship/categories.phtml            app/design/adminhtml/default/default/template/udropship/categories.phtml
    ...
    
  2. Suggested by @ottonet – instructions and download from: https://gist.github.com/ottonet/2841937ac4716578673a

    This is one line shell scrip that creates modman definitions. For example if the extension contains 56 files, then the modman file will contain 56 lines. Compact and quick solution. Just works! If you don’t mind that the modman file will have too many lines, then just use it!

    1. Create the shell script from the snippet presented on the download page. Call the shell script “makemod”
    2. Make the shell script executable – chmod +x makemod
    3. Run the shell script inside the root folder of the third party extension – ./makemod
    4. The modman file will be generate in the root folder of the extension
  3. Suggested by @fschmengler (package2modman) – instructions and download from: https://gist.github.com/schmengler/88fa071822a95224373f

    This script reads the Magento Connect 2.0 package.xml and creates the modman directives based on file paths described in package.xml. The shell script just works, but of course before you run the script you must have the file package.xml in the root folder of the third party extension. To summarise the extension creates a modman file of directly downloaded Magento Connect 2.0 packages.

    As you will see at the script download page, the shell script must access “app/Mage.php”, so make sure that you modify the line require_once(__DIR__ . “/../www/app/Mage.php”); in order to make the extension works for your development environment.

    Example usage:

    php package2modman.php path/to/package.xml > path/to/modman
    
  4. PHP Storm plugin (work in progress) by @SimonSprankel

    In twitter discussion @SimonSprankel mentioned that he is working on PHP Storm plugin for automated modman files generation. As the work is in progress I am excited to see the plugin in the near future and to use it on my projects.

    PHP Storm modman generator plugin - tweet by Simon Sprankel

Your thoughts / questions?

Tweet about this on TwitterShare on LinkedInShare on Google+Share on FacebookEmail this to someone

Tsvetan Stoychev

Tsvetan aka. Cecko is the founder of Cecko's Lab. He is Magento addicted since Magento CE 1.2.1.2 and has worked on over 30 Magento projects. At the moment he is in charge to take care about the money flow of the company, to keep constant communication with the clients and to keep the people in the office busy.

More Posts

Follow Me:
TwitterLinkedIn

  • SeoFood

    I make my mapings via json. So I would ike to get a phpstorm plugin for that. I already use magicento. Maybe I will write a Feature request for that.

  • ceckoslab

    I am looking forward to see it, but I am curious why JSON when we already have modman as one of the standards in the Magento community? What do you do with the third party extensions that have modman file, do you generate JSON for them?

  • I also wrote one snippet, but recently I also found (1) solution and switched to it.

  • Pingback: #MagentoMonday Community Digest 2015.07.20 | Maxanoo()

  • Pingback: Magento-Neuigkeiten #43()

  • Chris Nolan

    Useful post, thanks. Solution (1) is nice for 95% of cases but the 5% make it sadly unreliable and ultimately unusable. Mainly it doesn’t exclude .svn files (or other hidden files you may not want) and is not flexible in terms of what can be included. E.g. if you have a file one level deep inside var/ (e.g. var/aoe_profiler.xml) then it won’t be included. Chasing around trying to find missing files is no fun. Solution (2) is much cleaner in that it is tranparent to understand the mechanism by which it works, so even though it can generate big modman files, I think it is the better solution.

  • Hello @disqus_wWFMpBBqiI:disqus,

    There is a magerun tool that I haven’t tested yet but may solve the problems you mentioned: https://github.com/fruitcakestudio/magerun-modman

    This is valuable feedback and I am going ping the community members so they may decided to improve their tools. What I think will be valuable in general case is if the toll give a feedback how many files are in the module and for how many files were created modman directives. In this way developers may have a clue that not all files were included in modman and that manual work is required.

    Have a good day.

  • Barryvdh

    Hey @disqus_wWFMpBBqiI:disqus and @ceckoslab:disqus,

    I understand, it’s a bit difficult to detect the best format. The readme/package.xml/svn/docs etc should be ignored, the rest not. But not everyone follows the same conventions.
    Similar for the rewriting of the paths, this isn’t always possible.

    I added a ‘–raw’ flag to the modman:generate command for my Magerun plugin (https://github.com/fruitcakestudio/magerun-modman ), so you can choose which option you need. For 95% of the cases it will probably work, but it’s always smart to check the generated output first.

  • Chris Nolan

    Hi @barryvdh:disqus nice to see this extension for magerun. I have been using the “find” command as I like how transparent it is but I will definitely give this a try too as I love magerun. Great to see so many people offering different solutions to this problem.

  • proxium

    Unfortunately @SimonSprankel didn’t continue working on the PHP Storm https://twitter.com/SimonSprankel/status/691956919318241280