This repository was archived by the owner on Dec 5, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPsDevToolsPlugin.php
More file actions
112 lines (95 loc) · 3.07 KB
/
PsDevToolsPlugin.php
File metadata and controls
112 lines (95 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/**
* SebSept Ps_dev_base - Tools for quality Prestashop Module development.
*
* Copyright (c) 2021 Sébastien Monterisi
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/MIT
*
* @author Sébastien Monterisi <contact@seb7.fr>
* @copyright since 2021 Sébastien Monterisi
* @license https://opensource.org/licenses/MIT MIT License
*/
declare(strict_types=1);
namespace SebSept\PsDevToolsPlugin\Composer;
use Composer\Composer;
use Composer\DependencyResolver\Operation\InstallOperation;
use Composer\EventDispatcher\EventSubscriberInterface;
use Composer\Installer\PackageEvent;
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
{
}
public function deactivate(Composer $composer, IOInterface $io): void
{
}
public function uninstall(Composer $composer, IOInterface $io): void
{
$io->info('You choose to remove SebSept/PsDevToolsPlugin :(');
$io->info('Can you tell me what\'s wrong with it ?');
$io->info('https://github.com/SebSept/ps_dev_base');
}
/**
* @return array<string, string>
*/
public function getCapabilities(): array
{
return [
'Composer\Plugin\Capability\CommandProvider' => PsDevToolsCommandProvider::class,
];
}
/**
* @return array<string, string|array<int, array<int, string>>>
*/
public static function getSubscribedEvents(): array
{
return [
'post-package-install' => 'preparefirstRun',
'post-update-cmd' => 'firstRun', // just to be the last output.
];
}
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) {
return;
}
// only for self installation
/** @var InstallOperation $operation */
$operation = $event->getOperation();
if ('sebsept/ps_dev_base' !== $operation->getPackage()->getName()) {
return;
}
$this->isFirstRun = true;
}
}