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
To do the non-development environment update without triggering any scripts, use the
--no-scriptscommand line switch for theupdatecommand:By default, Composer scripts are only executed1 in the base package2. So you could have one package for development and in the live environment make it a dependency of the live system.
Apart from that, I do not see any way to differentiate scripts automatically.
This answer is back from 2012, the additional options in order of appearance can now safely be listed. As the list is composer-only and the original question smells to fall for x/y, the general answer is to use a build manager.
But turns out this could be done already at the day of asking, as in this composer-json example:
__callStatic, e.g.composer::dev-post-update-cmd. ifin_array('--dev', $_SERVER['argv'])then$eventDispatcher->dispatchCommandEvent($name).--devis now default and henceforth optional,--no-devrequired for not--devscript dispatching. this effectively changes the command-line in question from:composer update --devrunning only to: not running oncomposer update --no-dev.$event->isDevMode()now available, also required for new second parameter on dispatching the script on the event dispatcher. Compare with answer by Christian Koch.autoload-devnow allows to not have the script class in--no-devautomatically by removing it fromautoload. this works b/c non-existing classes fall-through w/o error.--devis deprecated.COMPOSER_DEV_MODEenvironment parameter now available in update/install/dumpautoload scripts. no inherit need any longer for the PHP script class, unless enviroment parameters do not work in your setup, then use a PHP class script for a workaround. Compare with answer by Veda.--devwill needlessly make composer fatal, at least this is announced. this closes the circle to pre-1.0.0-alpha7 which also failed on the opposite,--no-dev. the command-line library in use then and yet in the future is not able to cope with-[-not]-argssymmetrically, and if the pair is divided and one must go, then it can only throw.References