updated script events
added new POST_ROOT_PACKGE_INSTALL and POST_CREATE_PROjECT event, triggered only in create-project changed create-package parameter 'package' to be optional, command now looks in working directory for composer project if no param is givenpull/1945/head
parent
b38db73611
commit
0ac5165f04
|
@ -26,6 +26,7 @@ use Composer\Repository\ComposerRepository;
|
||||||
use Composer\Repository\CompositeRepository;
|
use Composer\Repository\CompositeRepository;
|
||||||
use Composer\Repository\FilesystemRepository;
|
use Composer\Repository\FilesystemRepository;
|
||||||
use Composer\Repository\InstalledFilesystemRepository;
|
use Composer\Repository\InstalledFilesystemRepository;
|
||||||
|
use Composer\Script\ScriptEvents;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
@ -51,7 +52,7 @@ class CreateProjectCommand extends Command
|
||||||
->setName('create-project')
|
->setName('create-project')
|
||||||
->setDescription('Create new project from a package into given directory.')
|
->setDescription('Create new project from a package into given directory.')
|
||||||
->setDefinition(array(
|
->setDefinition(array(
|
||||||
new InputArgument('package', InputArgument::REQUIRED, 'Package name to be installed'),
|
new InputArgument('package', InputArgument::OPTIONAL, 'Package name to be installed', 'local'),
|
||||||
new InputArgument('directory', InputArgument::OPTIONAL, 'Directory where the files should be created'),
|
new InputArgument('directory', InputArgument::OPTIONAL, 'Directory where the files should be created'),
|
||||||
new InputArgument('version', InputArgument::OPTIONAL, 'Version, will defaults to latest'),
|
new InputArgument('version', InputArgument::OPTIONAL, 'Version, will defaults to latest'),
|
||||||
new InputOption('stability', 's', InputOption::VALUE_REQUIRED, 'Minimum-stability allowed (unless a version is specified).', 'stable'),
|
new InputOption('stability', 's', InputOption::VALUE_REQUIRED, 'Minimum-stability allowed (unless a version is specified).', 'stable'),
|
||||||
|
@ -133,6 +134,11 @@ EOT
|
||||||
|
|
||||||
public function installProject(IOInterface $io, $config, $packageName, $directory = null, $packageVersion = null, $stability = 'stable', $preferSource = false, $preferDist = false, $installDevPackages = false, $repositoryUrl = null, $disableCustomInstallers = false, $noScripts = false, $keepVcs = false, $noProgress = false)
|
public function installProject(IOInterface $io, $config, $packageName, $directory = null, $packageVersion = null, $stability = 'stable', $preferSource = false, $preferDist = false, $installDevPackages = false, $repositoryUrl = null, $disableCustomInstallers = false, $noScripts = false, $keepVcs = false, $noProgress = false)
|
||||||
{
|
{
|
||||||
|
if ($packageName === 'local') {
|
||||||
|
$installedFromVcs = false;
|
||||||
|
goto installDependencies;
|
||||||
|
}
|
||||||
|
|
||||||
$stability = strtolower($stability);
|
$stability = strtolower($stability);
|
||||||
if ($stability === 'rc') {
|
if ($stability === 'rc') {
|
||||||
$stability = 'RC';
|
$stability = 'RC';
|
||||||
|
@ -219,6 +225,12 @@ EOT
|
||||||
// clean up memory
|
// clean up memory
|
||||||
unset($dm, $im, $config, $projectInstaller, $sourceRepo, $package);
|
unset($dm, $im, $config, $projectInstaller, $sourceRepo, $package);
|
||||||
|
|
||||||
|
|
||||||
|
installDependencies:
|
||||||
|
if ($noScripts === false) {
|
||||||
|
// dispatch event
|
||||||
|
$this->getComposer()->getEventDispatcher()->dispatchCommandEvent(ScriptEvents::POST_ROOT_PACKAGE_INSTALL, $installDevPackages);
|
||||||
|
}
|
||||||
// install dependencies of the created project
|
// install dependencies of the created project
|
||||||
$composer = Factory::create($io);
|
$composer = Factory::create($io);
|
||||||
$installer = Installer::create($io, $composer);
|
$installer = Installer::create($io, $composer);
|
||||||
|
@ -236,6 +248,11 @@ EOT
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($noScripts === false) {
|
||||||
|
// dispatch event
|
||||||
|
$this->getComposer()->getEventDispatcher()->dispatchCommandEvent(ScriptEvents::POST_CREATE_PROJECT, $installDevPackages);
|
||||||
|
}
|
||||||
|
|
||||||
$hasVcs = $installedFromVcs;
|
$hasVcs = $installedFromVcs;
|
||||||
if (!$keepVcs && $installedFromVcs
|
if (!$keepVcs && $installedFromVcs
|
||||||
&& (
|
&& (
|
||||||
|
|
|
@ -127,4 +127,24 @@ class ScriptEvents
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
const POST_AUTOLOAD_DUMP = 'post-autoload-dump';
|
const POST_AUTOLOAD_DUMP = 'post-autoload-dump';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The POST_ROOT_PACKAGE_INSTALL event occurs after the root package has been installed.
|
||||||
|
*
|
||||||
|
* The event listener method receives a Composer\Script\PackageEvent instance.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
const POST_ROOT_PACKAGE_INSTALL = 'post-root-package-install';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The POST_CREATE_PROJECT event occurs after the create-project command has been executed.
|
||||||
|
* Note: Event occurs after POST_INSTALL_CMD
|
||||||
|
*
|
||||||
|
* The event listener method receives a Composer\Script\PackageEvent instance.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
const POST_CREATE_PROJECT = 'post-create-project';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue