Skip to content

Commit

Permalink
[Composer] Détection des configs existantes sur le pre-hook d'install…
Browse files Browse the repository at this point in the history
…ation

fix #5
  • Loading branch information
heristop authored Feb 21, 2023
1 parent bd04cac commit 1018b75
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 20 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,5 @@ jobs:

- name: Run the static tools with grumphp
run: |
mkdir tests config public
touch src/Kernel.php
touch public/index.php
mv psalm.qualytou.xml psalm.xml
php vendor/bin/grumphp run --no-interaction
27 changes: 14 additions & 13 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
<?php

$finder = (new PhpCsFixer\Finder())
->in(__DIR__ . '/')
->exclude([
'vendor',
'var',
'config',
'public'
])
->notPath('src/Kernel.php')
->notPath('public/index.php')
->notPath('tests/bootstrap.php')
;

return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules(
Expand Down Expand Up @@ -51,28 +64,16 @@
'explicit_string_variable' => true,
'fully_qualified_strict_types' => true,
'global_namespace_import' => ['import_classes' => false, 'import_constants' => false, 'import_functions' => false],
'linebreak_after_opening_tag' => true,
'list_syntax' => ['syntax' => 'short'],
'mb_str_functions' => true,
'multiline_comment_opening_closing' => true,
'multiline_whitespace_before_semicolons' => ['strategy' => 'new_line_for_chained_calls'],
'no_alternative_syntax' => true,
'no_superfluous_elseif' => true,
'ordered_imports' => true,
'ordered_interfaces' => true,
]
)
->setRiskyAllowed(true)
->setFinder((new PhpCsFixer\Finder())
->in(__DIR__ . '/')
->exclude([
'vendor',
'var',
'config',
'public'
])
->notPath('src/Kernel.php')
->notPath('public/index.php')
->notPath('tests/bootstrap.php'))
->setFinder($finder)
->setCacheFile('.php-cs-fixer.cache')
;
15 changes: 15 additions & 0 deletions psalm.qualytou.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<psalm
errorLevel="1"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
32 changes: 28 additions & 4 deletions src/Composer/InstallFilesPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,25 @@ public function postPackageInstall(PackageEvent $event): void
}

$name = $operation->getPackage()->getName();

$this->io->write('<fg=yellow>Création des fichiers de configuration :</>');

$overrideAllQuestion = $this->io->askConfirmation('Écraser les configurations existantes, par défaut (oui/non) ? [<fg=yellow>oui</>] ', true);

foreach (self::FILES as $file) {
if ($filesystem->exists($file) === true && $overrideAllQuestion !== true) {
$overrideFileQuestion = $this->io->askConfirmation(sprintf('Le fichier de configuration %s existe déjà. Voulez-vous l\'écraser (oui/non) ? [<fg=yellow>oui</>] ', $file), true);

if ($overrideFileQuestion === false) {
$this->io->write(sprintf('<info>Le fichier de configuration %s a été conservé.</info>', $file));

continue;
}
}

$filesystem->copy($vendorBin . \DIRECTORY_SEPARATOR . $name . \DIRECTORY_SEPARATOR . $file, $file);
$this->io->write(sprintf('<fg=yellow>Le fichier de configuration %s a été copié</>', $file));
}
$this->io->write('<fg=yellow>Qualytou a installé les fichiers nécessaires à son fonctionnement !<fg=yellow>');
}

public function prePackageUninstall(PackageEvent $event): void
Expand All @@ -96,9 +111,18 @@ public function prePackageUninstall(PackageEvent $event): void
}

$filesystem = new Filesystem();
foreach (self::FILES as $file) {
$filesystem->remove($file);

$this->io->write('<fg=yellow>Détection des fichiers installés :</>');

$deleteAllQuestions = $this->io->askConfirmation('Supprimer les fichiers de configurations existants (oui/non) ? [<fg=yellow>oui</>] ', true);

if ($deleteAllQuestions === true) {
foreach (self::FILES as $file) {
if ($filesystem->exists($file) === true) {
$filesystem->remove($file);
$this->io->write(sprintf('<info>Le fichier de configuration %s a été supprimé.</info>', $file));
}
}
}
$this->io->write('<fg=yellow>Qualytou a supprimé les fichiers de configuration !<fg=yellow>');
}
}

0 comments on commit 1018b75

Please sign in to comment.