Richard Knop Richard Knop - 4 months ago 30
PHP Question

Composer - run scripts only in dev environment

This is my composer.json file:

"require": {
"php": ">=5.4",
"zendframework/zendframework": "2.*",
"doctrine/doctrine-module": "dev-master",
"doctrine/doctrine-orm-module": "0.*",
"gedmo/doctrine-extensions": "dev-master"
},
"require-dev": {
"phpunit/phpunit": "3.7.*"
},
"scripts": {
"post-update-cmd": [
"rm -rf vendor/Behat",
"git clone git://github.com/Behat/Behat.git",
"cp composer.phar Behat/composer.phar",
"cd Behat && git submodule update --init",
"cd Behat && php composer.phar install",
"cd Behat && php composer.phar require guzzle/guzzle:3.0.*",
"mv Behat vendor/Behat",
"ln -sf ../Behat/bin/behat vendor/bin/"
]
}


How can I make it so the scripts are only run in the dev environment?

Basically I want the scripts to run only when I call:

php composer.phar update --dev

Answer

To do the non-development environment update without triggering any scripts, use the --no-scripts command line switch for the update command:

php composer.phar update --no-scripts
                         ^^^^^^^^^^^^

By default Composer scripts are only executed in the base package. So you could have one package for development and in the life environment make it a dependency of the live system.

Apart from that I do not see any way to differentiate scripts automatically.