magento-hackathon / magento-composer-installer

Composer installer for Magento modules
210 stars 154 forks source link

Add ability to translate path mapping prefixes #72

Closed pspiller closed 10 years ago

pspiller commented 10 years ago

This pull request adds the ability to specify a set of translations that are applied to the path mappings magento-composer-installer uses to symlink extension files. This is useful if some types of extension files need to be linked into non-standard locations.

We maintain a Magento fork called Mercator (https://github.com/mercator). One change we made in Mercator was to put web-accessible files (CSS, JS, images) under a 'public' directory. This can then be used as the web server's document root, preventing accidentally exposing private files (i.e. local.xml).

This change to the file structure means that extensions that include public files need to be handled correctly. We use Composer to manage the extensions included in Mercator, so one option would have been to rewrite the modman files/composer.json map sections/etc for all of them. However, this required making backwards-incompatible changes and made it harder to add extensions. Instead, we modified magento-composer-installer to allow specifying a set of transformations. These are applied to each path mapping, and allow us to have web-accessible files automatically moved into the public directory. This allows extensions to be installed without changing their path mapping information. We thought this functionality might be useful to anybody running a similarly-modified version of Magento.

For example, the set of path mappings we specify in Mercator's composer.json are:

    "extra": {
        "path-mapping-translations": {
            "js/":      "public/js/",
            "media/":   "public/media/",
            "skin/":    "public/skin/"
        }
    }

A partial example of a modman file used by one of the included extensions:

app/code/community/BL/CustomGrid/               app/code/community/BL/CustomGrid/
app/etc/modules/BL_CustomGrid.xml               app/etc/modules/BL_CustomGrid.xml
app/locale/fr_FR/BL_CustomGrid.csv              app/locale/fr_FR/BL_CustomGrid.csv
js/bl/customgrid/                               js/bl/customgrid/
skin/adminhtml/default/default/bl/customgrid/   skin/adminhtml/default/default/bl/customgrid/

With the above path mappings in place, when this modman file is processed it will be interpreted as:

app/code/community/BL/CustomGrid/               app/code/community/BL/CustomGrid/
app/etc/modules/BL_CustomGrid.xml               app/etc/modules/BL_CustomGrid.xml
app/locale/fr_FR/BL_CustomGrid.csv              app/locale/fr_FR/BL_CustomGrid.csv
js/bl/customgrid/                               public/js/bl/customgrid/
skin/adminhtml/default/default/bl/customgrid/   public/skin/adminhtml/default/default/bl/customgrid/

The 'skin' and 'js' files will be linked into place under the public directory, while everything that wasn't translated will be linked as normal.

Vinai commented 10 years ago

Thanks for your PR - interested to get @Flyingmana 's input on this since he has been very active on the magento-composer-installer project recently. Without having looked at the code, I generally like added fleibility in regards to file system path structures.

Flyingmana commented 10 years ago

Thank you very much for this contribution, I like the Idea. I will test this when I have more Time again.

Also I am not sure about the way you have implemented this, but this can get refactored later from me :)

andkirby commented 9 years ago

Guys, is there any documentation about this?

And another question... Can I describe mapping in the package? Ie, I require a package in magento, and I need no to describe a map here.

Flyingmana commented 9 years ago

@andkirby there is documentation in the readme and the docs directory. I assume your search for the normal mapping via a modman file, as the here implemented feature does not make sense on package level.

We could also use another communication channel like mail, irc or gitter if you need assistance.

andkirby commented 9 years ago

Ok, thanks! You know, I've used feature "map" in "extra". So, my packages has following:

    "extra": {
      "map": [
        ["src/app/bootstrap.php", "app/"],
        ["src/app/autoload.php", "app/"],
        ["src/dev/", "dev/"],
        ["src/lib/Magento/", "lib/Magento/"]
      ]
    }

In this case I need no to describe deploying mapping.

Thanks for your help! :)