refactor(plugin): inherit from topfloor/composer-cleanup-vcs-dirs

This commit is contained in:
Jérémy Dufraisse 2023-03-13 13:55:07 +01:00
parent 363d8c7491
commit 4ae6f770d0
3 changed files with 61 additions and 54 deletions

View File

@ -19,7 +19,11 @@
"source": "https://git.defis.info/SeaCMS/composer-plugin"
},
"require": {
"composer-plugin-api": "^2.3"
"composer-plugin-api": "^2.3",
"topfloor/composer-cleanup-vcs-dirs": "^1.1"
},
"replace": {
"symfony/finder": "*"
},
"autoload": {
"psr-4": {
@ -27,8 +31,11 @@
}
},
"extra": {
"class": "Seacms\\ComposerInstaller\\Plugin",
"plugin-modifies-downloads": false,
"plugin-modifies-install-path": false
"class": "Seacms\\ComposerInstaller\\Plugin"
},
"config": {
"allow-plugins": {
"topfloor/composer-cleanup-vcs-dirs": false
}
}
}

39
src/Handler.php Normal file
View File

@ -0,0 +1,39 @@
<?php
/**
* SPDX-License-Identifier: EUPL-1.2
* Authors: see /README.md
*/
namespace Seacms\ComposerInstaller;
use SplFileInfo;
use TopFloor\ComposerCleanupVcsDirs\Handler as ParentHandler;
class Handler extends ParentHandler
{
/**
* @param $parentDir
* @param bool $excludeRoot
* @return SplFileInfo[]
*/
public function getVcsDirs($parentDir, $excludeRoot = false) {
$dirs = [];
if (!is_link($parentDir) && is_dir($parentDir) && is_dir("$parentDir/.git")){
$dirs[] = new SplFileInfo("$parentDir/.git");
}
return $dirs;
}
/**
* @param array $dirs
*/
public function deleteVcsDirs(array $dirs) {
/** @var SplFileInfo $dir */
foreach ($dirs as $dir) {
// $this->fs->removeDirectory($dir->getRealPath());
}
}
}

View File

@ -9,19 +9,17 @@ namespace Seacms\ComposerInstaller;
use Composer\Composer;
use Composer\Config;
use Composer\EventDispatcher\EventSubscriberInterface;
use Composer\Installer\PackageEvent;
use Composer\Installer\PackageEvents;
use Composer\Json\JsonFile;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;
use Seacms\ComposerInstaller\Handler;
use Seacms\ComposerInstaller\NotFoundFileException;
use TopFloor\ComposerCleanupVcsDirs\Plugin as ParentPlugin;
/**
* Composer plugin to install or not packages from local path
*/
class Plugin implements PluginInterface, EventSubscriberInterface
class Plugin extends ParentPlugin
{
/**
* composer instance
@ -34,29 +32,16 @@ class Plugin implements PluginInterface, EventSubscriberInterface
*/
protected $io;
/**
* Returns an array of event names this subscriber wants to listen to.
* @return array<string, string|array{0: string, 1?: int}|array<array{0: string, 1?: int}>> The event names to listen to
*/
public static function getSubscribedEvents(){
return [
PackageEvents::PRE_PACKAGE_UPDATE => 'prePackageUpdate',
];
}
public function prePackageUpdate(PackageEvent $event)
{
$event->getIO()->write("<info>Test : {$event->getOperation()}</info>");
}
/**
* Apply plugin modifications to Composer
*
* @return void
* @param Composer $composer
* @param IOInterface $io
*/
public function activate(Composer $composer, IOInterface $io){
public function activate(Composer $composer, IOInterface $io) {
$this->composer = $composer;
$this->io = $io;
$this->handler = new Handler($composer, $io);
try {
$this->updateConfig($this->getConfigJsonFile());
} catch (NotFoundFileException $ex){
@ -64,30 +49,6 @@ class Plugin implements PluginInterface, EventSubscriberInterface
}
}
/**
* Remove any hooks from Composer
*
* This will be called when a plugin is deactivated before being
* uninstalled, but also before it gets upgraded to a new version
* so the old one can be deactivated and the new one activated.
*
* @return void
*/
public function deactivate(Composer $composer, IOInterface $io){
}
/**
* Prepare the plugin to be uninstalled
*
* This will be called after deactivate.
*
* @return void
*/
public function uninstall(Composer $composer, IOInterface $io){
}
/**
* get config.json File from root path
* @return array ['config' => $config,'path'=>path]