Add new inline command stub

This commit is contained in:
Damian Mooyman 2017-07-07 15:47:49 +12:00
parent 0781c4a486
commit 8c0c7cfdbf
No known key found for this signature in database
GPG Key ID: 78B823A10DE27D1A
4 changed files with 77 additions and 3 deletions

View File

@ -0,0 +1,30 @@
<?php
namespace SilverStripe\RecipePlugin;
use Composer\Command\BaseCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class InlineRecipeCommand extends BaseCommand
{
public function configure()
{
$this->setName('inline');
$this->setDescription('Invoke this command to inline a recipe into your root composer.json');
$this->addArgument(
'recipe',
InputArgument::REQUIRED,
'Recipe name to inline. Must be of type '
. RecipePlugin::RECIPE
. ' and be included in the root as a direct dependency'
);
$this->addUsage('composer inline silverstripe/recipe-blogging');
}
public function execute(InputInterface $input, OutputInterface $output)
{
parent::execute($input, $output); // TODO: Change the autogenerated stub
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace SilverStripe\RecipePlugin;
use Composer\Command\BaseCommand;
use Composer\Plugin\Capability\CommandProvider;
class RecipeCommandProvider implements CommandProvider
{
/**
* Retrieves an array of commands
*
* @return BaseCommand[]
*/
public function getCommands()
{
return [
new InlineRecipeCommand()
];
}
}

View File

@ -91,6 +91,11 @@ class RecipeInstaller extends LibraryInstaller {
*/
public function installLibrary(PackageInterface $package)
{
// Check if silverstripe-recipe type
if ($package->getType() !== RecipePlugin::RECIPE) {
return;
}
// Copy project files to root
$destinationPath = getcwd();
$name = $package->getName();

View File

@ -10,16 +10,26 @@ use Composer\EventDispatcher\EventSubscriberInterface;
use Composer\Installer\PackageEvent;
use Composer\IO\IOInterface;
use Composer\Package\PackageInterface;
use Composer\Plugin\Capable;
use Composer\Plugin\PluginInterface;
use Composer\Plugin\Capability\CommandProvider;
/**
* Register the RecipeInstaller
*
* Credit to http://stackoverflow.com/questions/27194348/get-package-install-path-from-composer-script-composer-api
*/
class RecipePlugin implements PluginInterface, EventSubscriberInterface
class RecipePlugin implements PluginInterface, EventSubscriberInterface, Capable
{
public function activate(Composer $composer, IOInterface $io) { }
/**
* Recipe type
*/
const RECIPE = 'silverstripe-recipe';
public function activate(Composer $composer, IOInterface $io)
{
}
public static function getSubscribedEvents()
{
@ -33,7 +43,8 @@ class RecipePlugin implements PluginInterface, EventSubscriberInterface
*
* @param PackageEvent $event
*/
public function installPackage(PackageEvent $event) {
public function installPackage(PackageEvent $event)
{
$package = $this->getOperationPackage($event);
if ($package) {
$installer = new RecipeInstaller($event->getIO(), $event->getComposer());
@ -58,4 +69,11 @@ class RecipePlugin implements PluginInterface, EventSubscriberInterface
}
return null;
}
public function getCapabilities()
{
return [
CommandProvider::class => RecipeCommandProvider::class
];
}
}