Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

hello command started after (self) package install #34

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Command/SebSept/HelloCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->getIO()->write('This command show some helps for usage of this package.');
var_dump($this->getIO()->isInteractive());
$this->getIO()->write('This command show some helps for usage of this package.'); // not displayed
$this->getIO()->askConfirmation('oi K');
$this->getIO()->write('<info>ee</info>');
$this->getIO()->error('implement me');
// throw new \Exception('implement me');

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Composer/PsDevToolsCommandProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class PsDevToolsCommandProvider implements CommandProvider
public function getCommands(): array
{
return [
// new HelloCommand(),
new HelloCommand(),
new PrestashopDevToolsPhpStan(),
new PrestashopDevToolsCsFixer(),
new IndexPhpFiller(),
Expand Down
40 changes: 31 additions & 9 deletions src/Composer/PsDevToolsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,20 @@
use Composer\IO\IOInterface;
use Composer\Plugin\Capable;
use Composer\Plugin\PluginInterface;
use Composer\Script\Event;
use Symfony\Component\Process\Process;

final class PsDevToolsPlugin implements PluginInterface, Capable, EventSubscriberInterface
{
/** @var bool */
private $isFirstRun = false;

public function activate(Composer $composer, IOInterface $io): void
{
$io->debug('Mon plugin est actif');
}

public function deactivate(Composer $composer, IOInterface $io): void
{
$io->debug('Mon plugin est inactif');
}

public function uninstall(Composer $composer, IOInterface $io): void
Expand All @@ -58,17 +61,39 @@ public function getCapabilities(): array
}

/**
* @return array<string, string>
* @return array<string, string|array<int, array<int, string>>>
*/
public static function getSubscribedEvents(): array
{
return [
'post-package-install' => 'hello',
'post-package-install' => 'preparefirstRun',
'post-update-cmd' => 'firstRun', // just to be the last output.
];
}

public function hello(PackageEvent $event): void
public function firstRun(Event $event): void
{
if (!$this->isFirstRun) {
return;
}

$event->getIO()->info(__CLASS__ . ' first run ...');

$i = new Process('composer psdt:hello'); // @phpstan-ignore-line
$i->enableOutput()
->setTty(true)
->start();
$i->wait();

$this->isFirstRun = false;
}

public function preparefirstRun(PackageEvent $event): void
{
if (!$event->getIO()->isInteractive()) {
return;
}

// this happen on post-package-install so it should be an InstallOperation
// however, for safety it's checked.
if (!$event->getOperation() instanceof InstallOperation) {
Expand All @@ -82,9 +107,6 @@ public function hello(PackageEvent $event): void
return;
}

$event->getIO()->write('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~');
$event->getIO()->write('~~ <fg=magenta>Congratulation !PsDevTool is now installed</>. ~~');
$event->getIO()->write('~~ run <info>composer list psdt</info> to get started. ~~');
$event->getIO()->write('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~');
$this->isFirstRun = true;
}
}