mirror of
https://github.com/silverstripe/recipe-plugin.git
synced 2024-10-22 14:05:55 +02:00
Add new inline command stub
This commit is contained in:
parent
0781c4a486
commit
8c0c7cfdbf
30
src/InlineRecipeCommand.php
Normal file
30
src/InlineRecipeCommand.php
Normal 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
|
||||
}
|
||||
}
|
21
src/RecipeCommandProvider.php
Normal file
21
src/RecipeCommandProvider.php
Normal 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()
|
||||
];
|
||||
}
|
||||
}
|
@ -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();
|
||||
|
@ -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
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user