Skip to content
Snippets Groups Projects
Commit 7ed07c01 authored by jurgenhaas's avatar jurgenhaas
Browse files

Provide both commands separately and trigger post package install script from composer.json

parent 7be50143
No related branches found
No related tags found
No related merge requests found
......@@ -30,5 +30,10 @@
},
"extra": {
"class": "LakeDrops\\DrupalSpoons\\Plugin"
},
"scripts": {
"post-package-install": [
"LakeDrops\\DrupalSpoons\\Plugin::postPackageInstall"
]
}
}
......@@ -14,7 +14,8 @@ class CommandProvider implements CommandProviderCapability {
*/
public function getCommands(): array {
return [
new DrupalSpoonsCommand(),
new PrepareComposerCommand(),
new PrepareProjectCommand(),
];
}
}
......@@ -50,7 +50,7 @@ class Handler {
$projectRoot = getcwd();
// Append DrupalSpoon related components to composer.json.
$jsonFile = new JsonFile($projectRoot . '/composer.json.disabled');
$jsonFile = new JsonFile($projectRoot . '/composer.disabled.json');
$content = [];
if ($jsonFile->exists()) {
$content = $jsonFile->read();
......@@ -58,7 +58,7 @@ class Handler {
$content = array_merge_recursive($content, $options);
$jsonFile->write($content);
$fs->remove($projectRoot . '/composer.json');
$fs->rename($projectRoot . '/composer.json.disabled', $projectRoot . '/composer.json');
$fs->rename($projectRoot . '/composer.disabled.json', $projectRoot . '/composer.json');
}
/**
......
......@@ -4,6 +4,7 @@ namespace LakeDrops\DrupalSpoons;
use Composer\Composer;
use Composer\EventDispatcher\EventSubscriberInterface;
use Composer\Installer\PackageEvent;
use Composer\IO\IOInterface;
use Composer\Plugin\Capable;
use Composer\Plugin\PluginInterface;
......@@ -43,19 +44,16 @@ class Plugin implements PluginInterface, EventSubscriberInterface, Capable {
*/
public static function getSubscribedEvents(): array {
return [
ScriptEvents::POST_INSTALL_CMD => 'configureComposerJson',
ScriptEvents::POST_UPDATE_CMD => 'configureProject',
];
}
/**
* Post install command event callback.
*
* @param \Composer\Script\Event $event
* The event that triggered the plugin.
* @param \Composer\Installer\PackageEvent $event
*/
public function configureComposerJson(Event $event) {
$this->handler->configureComposerJson();
public static function postPackageInstall(PackageEvent $event) {
$handler = new Handler($event->getComposer(), $event->getIO());
$handler->configureComposerJson();
}
/**
......
<?php
namespace LakeDrops\DrupalSpoons;
use Composer\Command\BaseCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class PrepareComposerCommand extends BaseCommand {
/**
* {@inheritdoc}
*/
protected function configure() {
$this->setName('drupalspoons:prepare');
$this->setDescription('Prepare composer.json for DrupalSpoons.');
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output) {
$handler = new Handler($this->getComposer(), $this->getIO());
$handler->configureComposerJson();
}
}
......@@ -6,14 +6,14 @@ use Composer\Command\BaseCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class DrupalSpoonsCommand extends BaseCommand {
class PrepareProjectCommand extends BaseCommand {
/**
* {@inheritdoc}
*/
protected function configure() {
$this->setName('lakedrops:drupalspoons');
$this->setDescription('Prepare Drupal project for CI and/or local tests.');
$this->setName('drupalspoons:configure');
$this->setDescription('Configure project for DrupalSpoons.');
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment