From 58245b6d4a6f86f557070ebd3ddb803dbdd79752 Mon Sep 17 00:00:00 2001 From: Roberto Butti Date: Sat, 16 Jul 2022 23:24:28 +0200 Subject: [PATCH 1/4] improving output command with Termwind --- .github/workflows/check-php81.yml | 2 +- .github/workflows/php.yml | 2 +- .github/workflows/test-template.yaml | 2 +- .github/workflows/test.yml | 2 +- composer.json | 7 +- .../views/laralens/term/checks.blade.php | 78 ++++++++++ resources/views/laralens/term/table.blade.php | 62 ++++++++ src/Console/LaraLensCommand.php | 133 ++---------------- src/Lens/Traits/TermOutput.php | 29 ++++ 9 files changed, 191 insertions(+), 126 deletions(-) create mode 100644 resources/views/laralens/term/checks.blade.php create mode 100644 resources/views/laralens/term/table.blade.php create mode 100644 src/Lens/Traits/TermOutput.php diff --git a/.github/workflows/check-php81.yml b/.github/workflows/check-php81.yml index b24cf77..ed7bb50 100644 --- a/.github/workflows/check-php81.yml +++ b/.github/workflows/check-php81.yml @@ -17,7 +17,7 @@ jobs: strategy: matrix: operating-system: [ubuntu-latest] - php-versions: [ '8.0','7.4','8.1' ] + php-versions: [ '8.0','8.1' ] dependency-stability: [ 'prefer-none' ] name: P${{ matrix.php-versions }} - L${{ matrix.laravel }} - ${{ matrix.dependency-stability }} - ${{ matrix.operating-system}} diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index c78568a..e13fd80 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -25,6 +25,6 @@ jobs: run: composer run-script test - name: PHP Syntax Checker (Lint) - uses: StephaneBour/actions-php-lint@7.2 + uses: StephaneBour/actions-php-lint@8.0 with: dir: './src' diff --git a/.github/workflows/test-template.yaml b/.github/workflows/test-template.yaml index 7c036df..13b50e8 100644 --- a/.github/workflows/test-template.yaml +++ b/.github/workflows/test-template.yaml @@ -16,7 +16,7 @@ jobs: strategy: matrix: operating-system: [ubuntu-latest] - php-versions: [ '8.1', '8.0','7.4' ] + php-versions: [ '8.1', '8.0' ] dependency-stability: [ prefer-stable ] name: P${{ matrix.php-versions }} - L${{ matrix.laravel }} - ${{ matrix.dependency-stability }} - ${{ matrix.operating-system}} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 308bab2..d97598b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: operating-system: [ubuntu-latest] - php-versions: [ '8.1', '8.0','7.4','7.3' ] + php-versions: [ '8.1', '8.0' ] dependency-stability: [ prefer-stable ] name: P${{ matrix.php-versions }} - L${{ matrix.laravel }} - ${{ matrix.dependency-stability }} - ${{ matrix.operating-system}} diff --git a/composer.json b/composer.json index 61d2f41..73a53e4 100755 --- a/composer.json +++ b/composer.json @@ -22,13 +22,14 @@ } ], "require": { - "php": "^7.2|^8.0", + "php": "^7.4|^8.0|^8.1", + "ext-json": "*", "guzzlehttp/guzzle": "^6.0|^7.0", "illuminate/support": "^6.0|^7.0|^8.0|^9.0", - "ext-json": "*" + "nunomaduro/termwind": "^1.13" }, "require-dev": { - "nunomaduro/larastan": "^0.7.2", + "nunomaduro/larastan": "^0.7.2|^1.0.0", "orchestra/testbench": "4.*|5.*|6.*|7.*", "phpunit/phpunit": "^8.0|^9.3", "psalm/plugin-laravel": "^1.5", diff --git a/resources/views/laralens/term/checks.blade.php b/resources/views/laralens/term/checks.blade.php new file mode 100644 index 0000000..713314a --- /dev/null +++ b/resources/views/laralens/term/checks.blade.php @@ -0,0 +1,78 @@ +
+ @if (sizeof($rows) > 0) +
+ + + + CHECK: issues found + +
+ @else +
+ + + + CHECK: everything looks good + +
+ @endif +
+ + @foreach ($rows as $row) + @php + $lineType = Arr::get($row, "lineType", HiFolks\LaraLens\ResultLens::LINE_TYPE_DEFAULT); + $label = Arr::get($row, "label", ""); + @endphp + + @if ($label === "*** HINT") +
+ + 💡 Hint: + + + + + {{ Arr::get($row, "value", "") }} + + +
+ @else +
+
+
+ + @if ($lineType === HiFolks\LaraLens\ResultLens::LINE_TYPE_ERROR) + ❌ + @elseif ($lineType === HiFolks\LaraLens\ResultLens::LINE_TYPE_WARNING) + ⚠️ + @else + ✔️ + @endif +  {{ Arr::get($row, "label", "")}} + + + + + + @if ($lineType === HiFolks\LaraLens\ResultLens::LINE_TYPE_ERROR) + + {{ Arr::get($row, "value", "")}} + + @elseif ($lineType === HiFolks\LaraLens\ResultLens::LINE_TYPE_WARNING) + + {{ Arr::get($row, "value", "")}} + + @else + + + {{ Str::replace("\\", "/", Arr::get($row, "value", "")) }} + + @endif + + +
+ @endif + @endforeach +
+
+
\ No newline at end of file diff --git a/resources/views/laralens/term/table.blade.php b/resources/views/laralens/term/table.blade.php new file mode 100644 index 0000000..ee36804 --- /dev/null +++ b/resources/views/laralens/term/table.blade.php @@ -0,0 +1,62 @@ +
+
+ + + + + + {{ $title }} + +
+
+ + @foreach ($rows as $row) + @php + $lineType = Arr::get($row, "lineType", HiFolks\LaraLens\ResultLens::LINE_TYPE_DEFAULT); + $label = Arr::get($row, "label", ""); + + @endphp + @if ($label === "*** HINT") +
+ + Hint: + + + + + {{ Arr::get($row, "value", "") }} + + +
+ @else +
+ + {{ Arr::get($row, "label", "")}} + + + + + + @if ($lineType === HiFolks\LaraLens\ResultLens::LINE_TYPE_ERROR) + + {{ Arr::get($row, "value", "")}} + + @elseif ($lineType === HiFolks\LaraLens\ResultLens::LINE_TYPE_WARNING) + + {{ Arr::get($row, "value", "")}} + + @else + + + {{ Str::replace("\\", "/", Arr::get($row, "value", "")) }} + + @endif + + +
+ @endif + @endforeach +
+
+ +
\ No newline at end of file diff --git a/src/Console/LaraLensCommand.php b/src/Console/LaraLensCommand.php index 2475ae5..0a4004b 100644 --- a/src/Console/LaraLensCommand.php +++ b/src/Console/LaraLensCommand.php @@ -3,6 +3,7 @@ namespace HiFolks\LaraLens\Console; use HiFolks\LaraLens\Lens\LaraLens; +use HiFolks\LaraLens\Lens\Traits\TermOutput; use HiFolks\LaraLens\ResultLens; use Illuminate\Console\Command; use Illuminate\Support\Arr; @@ -10,6 +11,8 @@ class LaraLensCommand extends Command { + use TermOutput; + private const TABLE_STYLES = 'default|borderless|compact|symfony-style-guide|box|box-double'; private const DEFAULT_STYLE = 'box-double'; private const DEFAULT_PATH = ''; @@ -54,138 +57,30 @@ private function allConfigs(): void $this->info(json_encode(config()->all(), JSON_PRETTY_PRINT)); } - private function formatCell($string, $width) - { - $retVal = ""; - if (strlen($string) > $width) { - $retVal = Str::limit($string, $width, ''); - } elseif (strlen($string) < $width) { - $retVal = str_pad($string, $width); - } else { - $retVal = $string; - } - return $retVal; - } - - private function printOutput(array $headers, array $rows): void - { - $rowsTable = []; - $rowsLine = []; - foreach ($rows as $key => $row) { - $label = Arr::get($row, "label", ""); - $value = Arr::get($row, "value", ""); - if (is_array($value)) { - $value = implode(",", $value); - } - $isLine = Arr::get($row, "isLine", false); - $lineType = Arr::get($row, "lineType", ResultLens::LINE_TYPE_DEFAULT); - if ( - strlen($value) > $this->widthValue || - $isLine || - $lineType === ResultLens::LINE_TYPE_ERROR || - $lineType === ResultLens::LINE_TYPE_WARNING - ) { - $rowsLine[] = $row; - } else { - $row["label"] = $this->formatCell($label, $this->widthLabel); - $row["value"] = $this->formatCell($value, $this->widthValue); - $rowsTable[] = [ $row["label"], $row["value"] ]; - } - } - /* - * table style: - * 'default' - * 'borderless' - * 'compact' - * 'symfony-style-guide' - * 'box' - * 'box-double' - */ - $this->table($headers, $rowsTable, $this->styleTable); - foreach ($rowsLine as $key => $line) { - $label = Arr::get($line, "label", ""); - $value = Arr::get($line, "value", ""); - $lineType = Arr::get($line, "lineType", ResultLens::LINE_TYPE_DEFAULT); - if ($label != "") { - $this->info($label . ":"); - } - if ($lineType === ResultLens::LINE_TYPE_ERROR) { - $this->error($value); - } elseif ($lineType === ResultLens::LINE_TYPE_WARNING) { - $this->warn($value); - } else { - $this->line($value); - } - } - } - - private function alertGreen($string): void - { - $length = Str::length(strip_tags($string)) + 12; - $this->info(str_repeat('*', $length)); - $this->info('* ' . $string . ' *'); - $this->info(str_repeat('*', $length)); - $this->output->newLine(); - } - - private function printChecks(array $rows): void - { - if (sizeof($rows) == 0) { - $this->alertGreen("CHECK: everything looks good"); - } else { - $this->alert("CHECK: issues found"); - } - $idx = 0; - foreach ($rows as $key => $row) { - $label = Arr::get($row, "label", ""); - $value = Arr::get($row, "value", ""); - $isLine = Arr::get($row, "isLine", false); - $lineType = Arr::get($row, "lineType", ResultLens::LINE_TYPE_DEFAULT); - if ( - ($label !== "") && - (($lineType === ResultLens::LINE_TYPE_ERROR) || - ResultLens::isMessageLine($lineType)) - ) { - $idx++; - $this->warn("--- " . $idx . " ------------------"); - $this->warn("*** " . $label); - } - if ($lineType === ResultLens::LINE_TYPE_ERROR) { - $this->error($value); - } elseif ($lineType === ResultLens::LINE_TYPE_WARNING) { - $this->warn($value); - } elseif ($lineType === ResultLens::LINE_TYPE_INFO) { - $this->info($value); - } else { - $this->comment($value); - } - } - } - private function overview($checkTable = "users", $columnSorting = "created_at", $show = self::OPTION_SHOW_ALL): void { $ll = new LaraLens(); if ($show & self::OPTION_SHOW_CONFIGS) { $output = $ll->getConfigs(); - $this->printOutput(["Config keys via config()", "Values"], $output->toArray()); + $this->printOutputTerm("Config keys via config()", $output->toArray()); } if ($show & self::OPTION_SHOW_RUNTIMECONFIGS) { $output = $ll->getRuntimeConfigs(); - $this->printOutput(["Runtime Configs", "Values"], $output->toArray()); + $this->printOutputTerm("Runtime Configs", $output->toArray()); $output = $ll->checkServerRequirements(); - $this->printOutput(["Laravel Requirements", "Values"], $output->toArray()); + $this->printOutputTerm("Laravel Requirements", $output->toArray()); } if ($show & self::OPTION_SHOW_RUNTIMECONFIGS) { $output = $ll->checkFiles(); - $this->printOutput(["Check files", "Values"], $output->toArray()); + $this->printOutputTerm("Check files", $output->toArray()); } if ($show & self::OPTION_SHOW_CONNECTIONS) { $output = $ll->getConnections($this->urlPath); - $this->printOutput(["Connections", "Values"], $output->toArray()); + $this->printOutputTerm("Connections", $output->toArray()); } if ($show & self::OPTION_SHOW_DATABASE) { $output = $ll->getDatabase($checkTable, $columnSorting); - $this->printOutput(["Database", "Values"], $output->toArray()); + $this->printOutputTerm("Database", $output->toArray()); } if ($show & self::OPTION_SHOW_MIGRATION) { try { @@ -201,22 +96,22 @@ private function overview($checkTable = "users", $columnSorting = "created_at", $e->getMessage(), "Check the Database configuration" ); - $this->printOutput(["Migration" , "result"], $r->toArray()); + $this->printOutputTerm("Migration", $r->toArray()); } } if ($show & self::OPTION_SHOW_PHPEXTENSIONS) { $output = $ll->getPhpExtensions(); - $this->printOutput(["PHP Extensions"], $output->toArray()); + $this->printOutputTerm("PHP Extensions", $output->toArray()); } if ($show & self::OPTION_SHOW_PHPINIVALUES) { $output = $ll->getPhpIniValues(); - $this->printOutput(["PHP ini config", "Values"], $output->toArray()); + $this->printOutputTerm("PHP ini config", $output->toArray()); } if ($show & self::OPTION_SHOW_OS) { $output = $ll->getOsConfigs(); - $this->printOutput(["Operating System", "Values"], $output->toArray()); + $this->printOutputTerm("Operating System", $output->toArray()); } - $this->printChecks($ll->checksBag->toArray()); + $this->printChecksTerm($ll->checksBag->toArray()); } diff --git a/src/Lens/Traits/TermOutput.php b/src/Lens/Traits/TermOutput.php new file mode 100644 index 0000000..aca7e07 --- /dev/null +++ b/src/Lens/Traits/TermOutput.php @@ -0,0 +1,29 @@ + $title, + 'rows' => $rows + ]) + ); + } + + public function printChecksTerm(array $rows): void + { + render( + view('lara-lens::laralens.term.checks', [ + 'rows' => $rows + ]) + ); + } +} From 9d05079c99366e3792a686f8855608e166f70ffe Mon Sep 17 00:00:00 2001 From: Antonio Dal Sie Date: Sun, 17 Jul 2022 12:50:32 +0200 Subject: [PATCH 2/4] Restyle checks and table blade --- .../views/laralens/term/checks.blade.php | 94 +++++++------------ resources/views/laralens/term/table.blade.php | 64 ++++++------- 2 files changed, 60 insertions(+), 98 deletions(-) diff --git a/resources/views/laralens/term/checks.blade.php b/resources/views/laralens/term/checks.blade.php index 713314a..02dc11a 100644 --- a/resources/views/laralens/term/checks.blade.php +++ b/resources/views/laralens/term/checks.blade.php @@ -1,78 +1,50 @@ -
+
@if (sizeof($rows) > 0) -
- - - - CHECK: issues found - -
+
+ CHECK: issues found + +
@else -
- - - - CHECK: everything looks good - -
+
+ CHECK: everything looks good + +
@endif
- - @foreach ($rows as $row) - @php + @foreach ($rows as $row) + @php $lineType = Arr::get($row, "lineType", HiFolks\LaraLens\ResultLens::LINE_TYPE_DEFAULT); $label = Arr::get($row, "label", ""); - @endphp - - @if ($label === "*** HINT") -
- - 💡 Hint: - - + @endphp + @if ($label === "*** HINT") +
+ 💡 Hint: - {{ Arr::get($row, "value", "") }} + {{ Arr::get($row, "value", "") }} -
- @else -
-
- + @else +
$lineType === HiFolks\LaraLens\ResultLens::LINE_TYPE_ERROR, + 'bg-yellow text-black' => $lineType === HiFolks\LaraLens\ResultLens::LINE_TYPE_WARNING, + 'bg-green text-white' => $lineType !== HiFolks\LaraLens\ResultLens::LINE_TYPE_ERROR + && $lineType !== HiFolks\LaraLens\ResultLens::LINE_TYPE_WARNING, + ])> + {{ Arr::get($row, "label", "")}} +
+
@if ($lineType === HiFolks\LaraLens\ResultLens::LINE_TYPE_ERROR) - ❌ - @elseif ($lineType === HiFolks\LaraLens\ResultLens::LINE_TYPE_WARNING) - ⚠️ - @else - ✔️ - @endif -  {{ Arr::get($row, "label", "")}} - - - - - - @if ($lineType === HiFolks\LaraLens\ResultLens::LINE_TYPE_ERROR) - {{ Arr::get($row, "value", "")}} - - @elseif ($lineType === HiFolks\LaraLens\ResultLens::LINE_TYPE_WARNING) - + @elseif ($lineType === HiFolks\LaraLens\ResultLens::LINE_TYPE_WARNING) {{ Arr::get($row, "value", "")}} - - @else - - + @else {{ Str::replace("\\", "/", Arr::get($row, "value", "")) }} - - @endif - - + @endif
- @endif - @endforeach -
+ @endif + @endforeach
-
\ No newline at end of file +
diff --git a/resources/views/laralens/term/table.blade.php b/resources/views/laralens/term/table.blade.php index ee36804..3a6612b 100644 --- a/resources/views/laralens/term/table.blade.php +++ b/resources/views/laralens/term/table.blade.php @@ -1,62 +1,52 @@ -
+
- - - - - - {{ $title }} - + {{ $title }} +
-
+
@foreach ($rows as $row) @php - $lineType = Arr::get($row, "lineType", HiFolks\LaraLens\ResultLens::LINE_TYPE_DEFAULT); - $label = Arr::get($row, "label", ""); - + $lineType = Arr::get($row, "lineType", HiFolks\LaraLens\ResultLens::LINE_TYPE_DEFAULT); + $label = Arr::get($row, "label", ""); @endphp @if ($label === "*** HINT") -
- - Hint: - +
+ Hint: - - - {{ Arr::get($row, "value", "") }} +
+ + {{ Arr::get($row, "value", "") }} -
+
@else -
+
{{ Arr::get($row, "label", "")}} - + - +
@if ($lineType === HiFolks\LaraLens\ResultLens::LINE_TYPE_ERROR) - - {{ Arr::get($row, "value", "")}} - + + {{ Arr::get($row, "value", "")}} + @elseif ($lineType === HiFolks\LaraLens\ResultLens::LINE_TYPE_WARNING) - - {{ Arr::get($row, "value", "")}} - + + {{ Arr::get($row, "value", "")}} + @else - - - {{ Str::replace("\\", "/", Arr::get($row, "value", "")) }} - + + {{ Str::replace("\\", "/", Arr::get($row, "value", "")) }} + @endif - - +
@endif @endforeach
- -
\ No newline at end of file + +
From d49e8cc096ed55d889fcfcb2523419cbb40b8854 Mon Sep 17 00:00:00 2001 From: Roberto Butti Date: Sun, 17 Jul 2022 16:59:20 +0200 Subject: [PATCH 3/4] update style --- CHANGELOG.md | 4 ++++ resources/views/laralens/term/table.blade.php | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3231c9f..9fe5bc1 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.3.0 - WIP +- Add Termwind package + + ## 0.2.7 - 2022-01-23 - Add Support for Laravel 9 - Add tests for PHP8.1 diff --git a/resources/views/laralens/term/table.blade.php b/resources/views/laralens/term/table.blade.php index 3a6612b..8064cca 100644 --- a/resources/views/laralens/term/table.blade.php +++ b/resources/views/laralens/term/table.blade.php @@ -28,7 +28,7 @@ -
+ @if ($lineType === HiFolks\LaraLens\ResultLens::LINE_TYPE_ERROR) {{ Arr::get($row, "value", "")}} @@ -42,7 +42,7 @@ {{ Str::replace("\\", "/", Arr::get($row, "value", "")) }} @endif -
+
@endif @endforeach From 476f025227642b19dc5631418f74ad6dccf8a25e Mon Sep 17 00:00:00 2001 From: Roberto Butti Date: Sun, 17 Jul 2022 17:02:07 +0200 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fe5bc1..7e9d3f7 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,9 @@ # Changelog -## 0.3.0 - WIP +## 0.3.0 - 2022-07-17 - Add Termwind package - +- Review console output, thanks also to @exodusanto +- Support for PHP 8.0 and greater ## 0.2.7 - 2022-01-23 - Add Support for Laravel 9