From 5397159ae2dcb98f397859965a65f3abc61cfe9b Mon Sep 17 00:00:00 2001 From: SebSept Date: Fri, 21 May 2021 21:25:53 +0200 Subject: [PATCH 1/4] added option --ckeck-only to index filler --- notes_bu | 74 ++++++++++++++++++++++++++ src/Command/SebSept/IndexPhpFiller.php | 60 +++++++++++++++++---- 2 files changed, 124 insertions(+), 10 deletions(-) create mode 100644 notes_bu diff --git a/notes_bu b/notes_bu new file mode 100644 index 0000000..fdba563 --- /dev/null +++ b/notes_bu @@ -0,0 +1,74 @@ +# todo + + +# todo secondaire + +- implementer l'installation d'un hook pre-commit +- implemeter la commande :hello +- integrer worfklow phpstan maison +- intégration workflow github - https://github.com/PrestaShopCorp/ pas mal d'actions, voir aussi celle de presta (sonst les mêmes ?) (comme https://github.com/PrestaShop/github-webhook-parser) +- ugrade d'un package +- ajouter ref à la page https://devdocs.prestashop.com/1.7/modules/testing/ci-cd/ + +# todo pour plus tard + +- comment installer phpstan ? phpstan est requi par prestashop-dev-tools mais pas inclu dedans. + pour le moment, il est inclu dans le composer du ce packages, c'est plus simple. + mais il pourrait être dans le configureTool de PrestashopDevToolsPhpStan. +- a l'install : note sur le niveau de phpstan + +## Todo vraiment plus tard +intégration phpunit +yaml lint : https://yamllint.readthedocs.io/en/v1.2.1/quickstart.html#installing-yamllint +task runner pour le lintage hors ide des ressources +intégration lint js +intégration lint html/css/scss +intégrer validation de module avec validateur prestashop ? + +## Todo en attente +modification header-stamp pour traiter les header sans 'prestashop' dedans. + vendor/prestashop/header-stamp/src/Command/UpdateLicensesCommand.php:336 + +## Mémoire + +pour install sans symlink : COMPOSER_MIRROR_PATH_REPOS=1 composer install + +# ressources + +lint js : .stylelintrc + - https://github.com/PrestaShop/stylelint-config + - https://github.com/PrestaShop/stylelint-browser-compatibility +eslint : https://github.com/PrestaShop/eslint-config + + +voir https://github.com/PrestaShop/example-modules + +----- + +# v2 + +## Install + +s'install en local avec : +COMPOSER_MIRROR_PATH_REPOS=1 composer require --dev sebsept/ps_dev_base:2.x-dev +ou +COMPOSER_MIRROR_PATH_REPOS=1 composer require --dev sebsept/ps_dev_base:dev-pre-commit-hook +COMPOSER_MIRROR_PATH_REPOS=1 composer require --dev sebsept/ps_dev_base:dev-auto_config_phpstan +en ayant ajouté ça au composer : + + "repositories": [ + { + "type": "path", + "url": "/home/http/perso/prestashop/examplemodule", + "package": { + "name": "sebsept/ps_dev_base" + } + } + ] + + + +prestashop/php-dev-tools +Commande init de php-dev-tools copie dossier /templates/phpstan/ dans tests/phpstan +Contient le fichier de config phpstan.neon, qui inclue lui-même un autre fichier de config du package + diff --git a/src/Command/SebSept/IndexPhpFiller.php b/src/Command/SebSept/IndexPhpFiller.php index 9c3c8df..7657224 100644 --- a/src/Command/SebSept/IndexPhpFiller.php +++ b/src/Command/SebSept/IndexPhpFiller.php @@ -20,9 +20,11 @@ namespace SebSept\PsDevToolsPlugin\Command\SebSept; +use Composer\IO\IOInterface; use Exception; use SebSept\PsDevToolsPlugin\Command\ScriptCommand; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Finder\Finder; @@ -41,11 +43,15 @@ protected function configure(): void $this->setHelp($this->getDescription() . <<<'HELP' This is a security requirement of Prestashop to avoid the contents to be listed. + + The command adds all the missing index.php files unless you add the --check-only option. + With --check-only option the command returns 1 if some files are missing. 0 if all required files are present. More informations on the official documentation. https://devdocs.prestashop.com/1.7/modules/sell/techvalidation-checklist/#a-file-indexphp-exists-in-each-folder HELP - ); + ) + ->addOption('check-only', null, InputOption::VALUE_NONE, 'Checks if index.php are missing'); parent::configure(); } @@ -57,10 +63,14 @@ public function getComposerScriptName(): string protected function execute(InputInterface $input, OutputInterface $output): int { $this->fs = new Filesystem(); + if ($input->getOption('check-only')) { + return $this->checkMissingIndexes(); + } + $this->getIO()->write('Adding missing index.php to all directories.' . PHP_EOL . 'Existing index.php are not replaced.'); try { - $this->recursivelyAddIndexes(); + $this->addMissingIndexFiles(); $this->getIO()->write('Done'); return 0; @@ -71,15 +81,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int } } - private function recursivelyAddIndexes(): void + private function addMissingIndexFiles(): void { - $directoryIterator = (new Finder()) - ->in($this->getcwd()) - ->directories() - ->exclude('vendor') - ->getIterator(); - - foreach ($directoryIterator as $fileInfo) { + foreach ($this->getDirectoryIterator() as $fileInfo) { $this->addIndex($fileInfo); } } @@ -92,6 +96,28 @@ private function addIndex(\SplFileInfo $splFileInfo): void $this->fs->copy($this->getSourceIndexPath(), $target); } + private function checkMissingIndexes(): int + { + $missingIndexFiles = []; + + foreach ($this->getDirectoryIterator() as $fileInfo) { + $indexPhpPath = $fileInfo->getPathname() . '/index.php'; + $this->fs->exists($indexPhpPath) ?: array_push($missingIndexFiles, $indexPhpPath); + } + + if (empty($missingIndexFiles)) { + $this->getIO()->write('Good : no missing index files.'); + + return 0; + } + + $this->getIO()->write(':( Missing index.php files.'); + $this->getIO()->write($missingIndexFiles, true, IOInterface::VERBOSE); + $this->getIO()->write(['Use -v option to list missing files', 'Remove --check-only option to add missing files.']); + + return 1; + } + private function getSourceIndexPath(): string { return __DIR__ . self::SOURCE_INDEX_FILE; @@ -106,4 +132,18 @@ private function getcwd(): string return $cwd; } + + /** + * @return \AppendIterator|\Iterator|\RecursiveIteratorIterator|\Symfony\Component\Finder\Iterator\CustomFilterIterator|\Symfony\Component\Finder\Iterator\DateRangeFilterIterator|\Symfony\Component\Finder\Iterator\DepthRangeFilterIterator|\Symfony\Component\Finder\Iterator\FilecontentFilterIterator|\Symfony\Component\Finder\Iterator\FilenameFilterIterator|\Symfony\Component\Finder\Iterator\FileTypeFilterIterator|\Symfony\Component\Finder\Iterator\PathFilterIterator|\Symfony\Component\Finder\Iterator\SizeRangeFilterIterator|\Symfony\Component\Finder\SplFileInfo[] + */ + private function getDirectoryIterator() + { + $directoryIterator = (new Finder()) + ->in($this->getcwd()) + ->directories() + ->exclude('vendor') + ->getIterator(); + + return $directoryIterator; + } } From 11c605239535bd6f6896d637a79aa72e62431e64 Mon Sep 17 00:00:00 2001 From: SebSept Date: Fri, 21 May 2021 23:42:08 +0200 Subject: [PATCH 2/4] added precommit script to check missing indexes composer psdt:fill-indexes --check-only -v --- src/Command/SebSept/PrecommitHook.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Command/SebSept/PrecommitHook.php b/src/Command/SebSept/PrecommitHook.php index 03d3978..2b7dbfb 100644 --- a/src/Command/SebSept/PrecommitHook.php +++ b/src/Command/SebSept/PrecommitHook.php @@ -130,7 +130,7 @@ public function getComposerScriptName(): string */ private function getComposerScripts(): array { - $scripts = ['composer validate']; + $scripts = ['composer validate', '@composer psdt:fill-indexes --check-only -v']; !(new PrestashopDevToolsCsFixer())->isToolConfigured() ?: array_push($scripts, 'vendor/bin/php-cs-fixer fix --dry-run --ansi'); !(new PrestashopDevToolsPhpStan())->isToolConfigured() From 0bc8a51c8021fdbee763d914c6d9834cde3b5c31 Mon Sep 17 00:00:00 2001 From: SebSept Date: Sat, 22 May 2021 21:51:44 +0200 Subject: [PATCH 3/4] IndexPhpFiller.php install it's composer script. --- src/Command/SebSept/IndexPhpFiller.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Command/SebSept/IndexPhpFiller.php b/src/Command/SebSept/IndexPhpFiller.php index 7657224..2d3540d 100644 --- a/src/Command/SebSept/IndexPhpFiller.php +++ b/src/Command/SebSept/IndexPhpFiller.php @@ -22,6 +22,7 @@ use Composer\IO\IOInterface; use Exception; +use SebSept\PsDevToolsPlugin\Command\Contract\PreCommitRegistrableCommand; use SebSept\PsDevToolsPlugin\Command\ScriptCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -29,7 +30,7 @@ use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Finder\Finder; -final class IndexPhpFiller extends ScriptCommand +final class IndexPhpFiller extends ScriptCommand implements PreCommitRegistrableCommand { const SOURCE_INDEX_FILE = '/../../../resources/index.php'; @@ -62,6 +63,8 @@ public function getComposerScriptName(): string protected function execute(InputInterface $input, OutputInterface $output): int { + $this->isComposerScriptDefined() ?: $this->addComposerScript(['composer psdt:fill-indexes']); + $this->fs = new Filesystem(); if ($input->getOption('check-only')) { return $this->checkMissingIndexes(); @@ -138,12 +141,15 @@ private function getcwd(): string */ private function getDirectoryIterator() { - $directoryIterator = (new Finder()) + return (new Finder()) ->in($this->getcwd()) ->directories() ->exclude('vendor') ->getIterator(); + } - return $directoryIterator; + public function getComposerPrecommitScriptContent(): ?string + { + return ''; } } From bbc4674735f38aba09e78cd78c875b5a530d28cf Mon Sep 17 00:00:00 2001 From: SebSept Date: Sat, 22 May 2021 21:59:05 +0200 Subject: [PATCH 4/4] IndexPhpFiller.php implements PreCommitRegistrableCommand so it's available in precommit hook. --- src/Command/SebSept/IndexPhpFiller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Command/SebSept/IndexPhpFiller.php b/src/Command/SebSept/IndexPhpFiller.php index 2d3540d..6daf04b 100644 --- a/src/Command/SebSept/IndexPhpFiller.php +++ b/src/Command/SebSept/IndexPhpFiller.php @@ -150,6 +150,6 @@ private function getDirectoryIterator() public function getComposerPrecommitScriptContent(): ?string { - return ''; + return 'composer psdt:fill-indexes --check-only'; } }