From ee7961a0f30649033ac0ee5985ddfe68fbc391d8 Mon Sep 17 00:00:00 2001 From: James Moran Date: Sat, 11 Jan 2014 14:42:34 -0500 Subject: [PATCH 1/2] Implemented Pre/Post Archive Script Events The script events `pre-archive-cmd` and `post-archive-cmd` can be used to perform any tasks necessary when archiving the composer project. This functionality can be used to run unit test or and other build process before archiving, and can be used to distribute the archive when completed --- src/Composer/Command/ArchiveCommand.php | 10 +++++++++- src/Composer/Script/ScriptEvents.php | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Composer/Command/ArchiveCommand.php b/src/Composer/Command/ArchiveCommand.php index 03e8600fa..7a57ca13b 100644 --- a/src/Composer/Command/ArchiveCommand.php +++ b/src/Composer/Command/ArchiveCommand.php @@ -17,6 +17,7 @@ use Composer\IO\IOInterface; use Composer\DependencyResolver\Pool; use Composer\Package\LinkConstraint\VersionConstraint; use Composer\Repository\CompositeRepository; +use Composer\Script\ScriptEvents; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -55,13 +56,20 @@ EOT protected function execute(InputInterface $input, OutputInterface $output) { - return $this->archive( + $this->getComposer()->getEventDispatcher()->dispatchScript(ScriptEvents::PRE_ARCHIVE_CMD); + + $returnCode = $this->archive( $this->getIO(), $input->getArgument('package'), $input->getArgument('version'), $input->getOption('format'), $input->getOption('dir') ); + + if (0 === $returnCode) { + $this->getComposer()->getEventDispatcher()->dispatchScript(ScriptEvents::POST_ARCHIVE_CMD); + } + return $returnCode; } protected function archive(IOInterface $io, $packageName = null, $version = null, $format = 'tar', $dest = '.') diff --git a/src/Composer/Script/ScriptEvents.php b/src/Composer/Script/ScriptEvents.php index 5f3eaafd8..64ecbc8c5 100644 --- a/src/Composer/Script/ScriptEvents.php +++ b/src/Composer/Script/ScriptEvents.php @@ -165,4 +165,22 @@ class ScriptEvents */ const POST_CREATE_PROJECT_CMD = 'post-create-project-cmd'; + /** + * The PRE_ARCHIVE_CMD event occurs before the update command is executed. + * + * The event listener method receives a Composer\Script\CommandEvent instance. + * + * @var string + */ + const PRE_ARCHIVE_CMD = 'pre-archive-cmd'; + + /** + * The POST_ARCHIVE_CMD event occurs after the status command is executed. + * + * The event listener method receives a Composer\Script\CommandEvent instance. + * + * @var string + */ + const POST_ARCHIVE_CMD = 'post-archive-cmd'; + } From c103b54991b5f5a3d8abfbd36589c32200004450 Mon Sep 17 00:00:00 2001 From: James Moran Date: Mon, 27 Jan 2014 19:45:20 -0500 Subject: [PATCH 2/2] updated documentation with pre/post archive events --- doc/articles/scripts.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/articles/scripts.md b/doc/articles/scripts.md index 06e7c784d..ff9c8b5bc 100644 --- a/doc/articles/scripts.md +++ b/doc/articles/scripts.md @@ -40,6 +40,8 @@ Composer fires the following named events during its execution process: installed, during the `create-project` command. - **post-create-project-cmd**: occurs after the `create-project` command is executed. +- **pre-archive-cmd**: occurs before the `archive` command is executed. +- **post-archive-cmd**: occurs after the `archive` command is executed. **NOTE: Composer makes no assumptions about the state of your dependencies prior to `install` or `update`. Therefore, you should not specify scripts that