2017 © Pedro Peláez
 

composer-plugin statics-merger

A composer plugin that symlinks static assets into the JH Magento Skeleton

image

wearejh/statics-merger

A composer plugin that symlinks static assets into the JH Magento Skeleton

  • Friday, March 10, 2017
  • by mikeymike
  • Repository
  • 16 Watchers
  • 8 Stars
  • 10,825 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 18 Versions
  • 4 % Grown

The README.md

Statics Merger

Build Status Scrutinizer Code Quality Scrutinizer Code Coverage, (*1)

A composer plugin aimed to simplify the workflow between the frontend and backend development teams. Static repositories that the frontend team use are added as a composer dependency to the project as type static., (*2)

The plugin hooks onto two composer commands install and update in which on completion will symlink all static packages as defined in their composer.json file., (*3)

Installation

This module is installable via Composer. If you have used the Magento Skeleton as a base module then you can just require this project and all the rest is done for you., (*4)

Magento 1

$ cd project-root
$ ./composer.phar require "wearejh/statics-merger:^2.0.0"

Magento 2

$ cd project-root
$ ./composer.phar require "wearejh/statics-merger:^3.0.0"

Upgrading 1.x to 2.x ?

It's recommended to first run composer update statics-merger --no-plugins after changing your composer.json and then run a composer update nothing to map the new configuration., (*5)

Note: Depending on the configuration changes you may also have to manually cleanup any remaining symlinks from the old mappings, (*6)

Usage

Statics project

If the composer.json file is not already there, create one with relevant information and commit it to the repo., (*7)

For this to work the statics repository requires the composer.json to have the type set to static., (*8)

Example Static Composer.json

{
    "name": "wearejh/{project-name}-static",
    "type": "static",
    "description": "Main theme for {project-name}",
    "keywords": ["jh", "statics"],
    "authors": [
        {
            "name": "JH",
            "email": "hello@wearejh.com",
            "homepage": "http://www.wearejh.com"
        }
    ]
}

Magento project

Within your projects composer.json you will need to ensure you have a few configurations set up., (*9)

In your require you will need to add any statics that you want and if private also add the repo., (*10)

Note: It's great at handling multiple static repositories :thumbsup:, (*11)

"require": {
    "wearejh/{project-name}-static": "dev-master"
},
"repositories": [
    {
        "type": "git",
        "url": "git@jh.git.beanstalkapp.com:/jh/{project-name}-static.git"
    }
]

In your extra you need the magento-root-dir set correctly and have defined the static-map for each static repository., (*12)

"extra":{
    "magento-root-dir": "htdocs/",
    "static-map" : {
        "wearejh/{project-name}-static": {
            "package/theme": [
                {
                    "src": "public/assets",
                    "dest": "assets"
                },
                {
                    "src": "public/assets/img/favicon*",
                    "dest": "/"
                },
                {
                    "src": "assets/images/catalog",
                    "dest": "images/catalog"
                }
            ]
        }
    }
}

The first key is the name of the repository which you have used in the require section, while inside there each key is the package/theme in which the example would map to skin/frontend/package/theme within your `magento-root-dir., (*13)

The package/theme array contains several objects defining the src and dest of the files. The src value is relevant to the root of the statics repository while the dest is relevant to the package/theme defined in the Magento project such as skin/frontend/package/theme/ within your magento-root-dir., (*14)

Need to map a static repo to more than 1 package or theme? No problem just add another package/theme array to your repos mappings, of course make sure you use a different name to any others to avoid overwriting., (*15)

Valid Mappings

Note: Globs require the dest to be a folder and not a file, whereas files and directories need to point to there corresponding full path which allows you to rename them if required. If you leave the dest blank on a glob it will map to the same source directory structure within your package/theme, (*16)

Files

Link an image into a different directory structure and rename, (*17)

{
    "src": "public/assets/img/awesome/cake.gif",
    "dest": "images/newcake.gif"
}
Directories

Linking a whole directory keeping all sub-dirs & files, (*18)

{
    "src": "public/assets",
    "dest": "assets"
}
Globs

You can also use globs which makes it pretty awesome! A great use case for this is favicons where you could have multiple at different resolutions with a set naming convention. To target them all you would simply use favicon* like in the default example below., (*19)

All favicons to root dir skin/frontend/package/theme/, (*20)

{
    "src": "favicon*",
    "dest": "/"
}

Final Notes

  • Use tags to explicitly pull in the static repositories
  • Don't forget to add the package/theme dir to your .gitignore otherwise you will add the statics files to the Magento repo, and everyone will hate you
  • You can amend statics directly from the vendor dir and push straight to the main repo, WIN!
  • Have fun !! :smile:

Problems?

If you find any problems or edge cases which may need to be accounted for within this composer plugin just open up an issue with as much detail as possible so it can be recreated., (*21)

Running Tests

$ cd vendor/wearejh/statics-merger
$ php composer.phar install
$ ./vendor/bin/phpunit

The Versions

10/03 2017

dev-master

9999999-dev

A composer plugin that symlinks static assets into the JH Magento Skeleton

  Sources   Download

MIT

The Requires

  • composer-plugin-api ^1.0

 

The Development Requires

plugin composer composer-plugin merger statics jh statics-merger

10/03 2017

4.0.3

4.0.3.0

A composer plugin that symlinks static assets into the JH Magento Skeleton

  Sources   Download

MIT

The Requires

  • composer-plugin-api ^1.0

 

The Development Requires

plugin composer composer-plugin merger statics jh statics-merger

10/03 2017

dev-develop

dev-develop

A composer plugin that symlinks static assets into the JH Magento Skeleton

  Sources   Download

MIT

The Requires

  • composer-plugin-api ^1.0

 

The Development Requires

plugin composer composer-plugin merger statics jh statics-merger

02/03 2017

4.0.2

4.0.2.0

A composer plugin that symlinks static assets into the JH Magento Skeleton

  Sources   Download

MIT

The Requires

  • composer-plugin-api ^1.0

 

The Development Requires

plugin composer composer-plugin merger statics jh statics-merger

02/03 2017

dev-bug/timouts

dev-bug/timouts

A composer plugin that symlinks static assets into the JH Magento Skeleton

  Sources   Download

MIT

The Requires

  • composer-plugin-api ^1.0

 

The Development Requires

plugin composer composer-plugin merger statics jh statics-merger

01/03 2017

4.0.1

4.0.1.0

A composer plugin that symlinks static assets into the JH Magento Skeleton

  Sources   Download

MIT

The Requires

  • composer-plugin-api ^1.0

 

The Development Requires

plugin composer composer-plugin merger statics jh statics-merger

01/03 2017

4.0.0

4.0.0.0

A composer plugin that symlinks static assets into the JH Magento Skeleton

  Sources   Download

MIT

The Requires

  • composer-plugin-api ^1.0

 

The Development Requires

plugin composer composer-plugin merger statics jh statics-merger

11/08 2016

3.0.0

3.0.0.0

A composer plugin that symlinks static assets into the JH Magento Skeleton

  Sources   Download

MIT

The Requires

  • composer-plugin-api ^1.0

 

The Development Requires

plugin composer composer-plugin merger statics jh statics-merger

08/10 2015

2.2.3

2.2.3.0

A composer plugin that symlinks static assets into the JH Magento Skeleton

  Sources   Download

MIT

The Requires

  • composer-plugin-api ^1.0

 

The Development Requires

plugin composer composer-plugin merger statics jh statics-merger

11/06 2015

2.2.2

2.2.2.0

A composer plugin that symlinks static assets into the JH Magento Skeleton

  Sources   Download

MIT

The Requires

  • composer-plugin-api ^1.0

 

The Development Requires

plugin composer composer-plugin merger statics jh statics-merger

14/05 2015

2.2.1

2.2.1.0

A composer plugin that symlinks static assets into the JH Magento Skeleton

  Sources   Download

MIT

The Requires

  • composer-plugin-api 1.0.0

 

The Development Requires

plugin composer composer-plugin merger statics jh statics-merger

14/05 2015

2.2.0

2.2.0.0

A composer plugin that symlinks static assets into the JH Magento Skeleton

  Sources   Download

MIT

The Requires

  • composer-plugin-api 1.0.0

 

The Development Requires

plugin composer composer-plugin merger statics jh statics-merger

12/05 2015

2.1.1

2.1.1.0

A composer plugin that symlinks static assets into the JH Magento Skeleton

  Sources   Download

MIT

The Requires

  • composer-plugin-api 1.0.0

 

The Development Requires

plugin composer composer-plugin merger statics jh statics-merger

23/02 2015

2.1.0

2.1.0.0

A composer plugin that symlinks static assets into the JH Magento Skeleton

  Sources   Download

MIT

The Requires

  • composer-plugin-api 1.0.0

 

The Development Requires

plugin composer composer-plugin merger statics jh statics-merger

16/02 2015

2.0.0

2.0.0.0

A composer plugin that symlinks static assets into the JH Magento Skeleton

  Sources   Download

MIT

The Requires

  • composer-plugin-api 1.0.0

 

The Development Requires

plugin composer composer-plugin merger statics jh statics-merger

20/01 2015

1.1.0

1.1.0.0

A composer plugin that symlinks static assets into the JH Magento Skeleton

  Sources   Download

MIT

The Requires

  • composer-plugin-api 1.0.0

 

The Development Requires

plugin composer composer-plugin merger statics jh statics-merger

15/10 2014

1.0.1

1.0.1.0

A composer plugin that symlinks static assets into the JH Magento Skeleton

  Sources   Download

MIT

The Requires

  • composer-plugin-api 1.0.0

 

The Development Requires

plugin composer composer-plugin merger statics jh statics-merger

01/10 2014

1.0.0

1.0.0.0

A composer plugin that symlinks static assets into the JH Magento Skeleton

  Sources   Download

MIT

The Requires

  • composer-plugin-api 1.0.0

 

The Development Requires

plugin composer composer-plugin merger statics jh statics-merger