From 9e8baa3a447728d2da07ba8afc5db0eb42f8fd4f Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Tue, 24 Dec 2024 00:24:38 +0000 Subject: [PATCH] Adds default command --- bin/peck | 41 +++++++++++++ composer.json | 14 +++-- src/Checkers/FileSystemChecker.php | 4 ++ src/Console/Commands/DefaultCommand.php | 81 +++++++++++++++++++++++++ 4 files changed, 134 insertions(+), 6 deletions(-) create mode 100755 bin/peck create mode 100644 src/Console/Commands/DefaultCommand.php diff --git a/bin/peck b/bin/peck new file mode 100755 index 0000000..3cdeb9e --- /dev/null +++ b/bin/peck @@ -0,0 +1,41 @@ +#!/usr/bin/env php +add( + new \Peck\Console\Commands\DefaultCommand(), +); + +$application->setDefaultCommand('default'); + +$application->run(); + + + + + + + + + + + diff --git a/composer.json b/composer.json index 7e34e32..1a0ab57 100644 --- a/composer.json +++ b/composer.json @@ -11,16 +11,18 @@ ], "require": { "php": "^8.3.0", + "nunomaduro/termwind": "^2.3", + "symfony/console": "^7.2.1", "symfony/finder": "^7.2", "tigitz/php-spellchecker": "^0.7.0" }, "require-dev": { - "laravel/pint": "^1.18.1", - "pestphp/pest": "^3.5.1", - "pestphp/pest-plugin-type-coverage": "^3.1", - "phpstan/phpstan": "^1.12.7", - "rector/rector": "^1.2.8", - "symfony/var-dumper": "^7.1.6" + "laravel/pint": "^1.18.3", + "pestphp/pest": "^3.7.1", + "pestphp/pest-plugin-type-coverage": "^3.2.1", + "phpstan/phpstan": "^1.12.13", + "rector/rector": "^1.2.10", + "symfony/var-dumper": "^7.2.0" }, "autoload": { "psr-4": { diff --git a/src/Checkers/FileSystemChecker.php b/src/Checkers/FileSystemChecker.php index afb1412..12fcb46 100644 --- a/src/Checkers/FileSystemChecker.php +++ b/src/Checkers/FileSystemChecker.php @@ -33,6 +33,10 @@ public function __construct( public function check(array $parameters): array { $filesOrDirectories = Finder::create() + ->ignoreDotFiles(true) + ->ignoreVCS(true) + ->ignoreUnreadableDirs() + ->ignoreVCSIgnored(true) ->in($parameters['directory']) ->getIterator(); diff --git a/src/Console/Commands/DefaultCommand.php b/src/Console/Commands/DefaultCommand.php new file mode 100644 index 0000000..12ea792 --- /dev/null +++ b/src/Console/Commands/DefaultCommand.php @@ -0,0 +1,81 @@ +handle([ + 'directory' => $directory = self::inferProjectPath(), + ]); + + foreach ($issues as $issue) { + $this->renderIssue($output, $issue, $directory); + } + + return $issues !== [] ? Command::FAILURE : Command::SUCCESS; + } + + /** + * Configures the current command. + */ + protected function configure(): void + { + $this->setDescription('Checks for misspellings in the given directory.'); + } + + protected function renderIssue(OutputInterface $output, Issue $issue, string $currentDirectory): void + { + renderUsing($output); + + $file = str_replace($currentDirectory, '.', $issue->file); + + render(<< + {$issue->misspelling->word} in {$file}. + + HTML); + } + + /** + * Infer the project's base directory from the environment. + */ + protected static function inferProjectPath(): string + { + $basePath = dirname(array_keys(ClassLoader::getRegisteredLoaders())[0]); + + return match (true) { + isset($_ENV['APP_BASE_PATH']) => $_ENV['APP_BASE_PATH'], + default => match (true) { + is_dir($basePath.'/src') => ($basePath.'/src'), + is_dir($basePath.'/app') => ($basePath.'/app'), + default => $basePath, + }, + }; + } +}