From bd58490d2d096f23520931288821461143a9807a Mon Sep 17 00:00:00 2001 From: Len Woodward Date: Fri, 11 Aug 2023 10:01:10 -0700 Subject: [PATCH 1/6] wip --- app/Commands/Audit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Commands/Audit.php b/app/Commands/Audit.php index da2c09c..48242b0 100644 --- a/app/Commands/Audit.php +++ b/app/Commands/Audit.php @@ -32,7 +32,7 @@ public function handle(): int ['key', 'value'], [ ['- Whisky -', ''], - ['installed globally?', Whisky::isInstalledGlobally() ? 'yes' : 'no'], + ['installed globally?', Whisky::isInstalledGlobally() ? 'yes (v'.(include Platform::getGlobalComposerHome().'/vendor/projektgopher/whisky/config/app.php')['version'].')' : 'no'], ['running globally?', Whisky::isRunningGlobally() ? 'yes' : 'no'], ['dogfooding?', Whisky::dogfooding() ? 'yes' : 'no'], ['base path', Whisky::base_path()], From 45a9117ada1b3535e080946a0024fa59f0bd33ed Mon Sep 17 00:00:00 2001 From: Len Woodward Date: Fri, 24 May 2024 10:57:07 -0700 Subject: [PATCH 2/6] remove comment --- app/Commands/Audit.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/app/Commands/Audit.php b/app/Commands/Audit.php index 48242b0..8490a4b 100644 --- a/app/Commands/Audit.php +++ b/app/Commands/Audit.php @@ -14,18 +14,6 @@ class Audit extends Command public function handle(): int { - // co-pilot things. Might be useful, might not. - // $this->table( - // ['Hook', 'Status', 'File', 'Scripts'], - // Hook::all()->map(function (Hook $hook): array { - // return [ - // $hook->name, - // $hook->status(), - // $hook->file(), - // $hook->scripts()->implode(PHP_EOL), - // ]; - // })->toArray() - // ); $platform = new Platform(); $this->table( From 63ebf2fd5339b3961aa3bc0decc55dca3d38fb22 Mon Sep 17 00:00:00 2001 From: Len Woodward Date: Fri, 24 May 2024 10:57:36 -0700 Subject: [PATCH 3/6] get global version from composer instead of filesystem --- app/Commands/Audit.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/Commands/Audit.php b/app/Commands/Audit.php index 8490a4b..bde1559 100644 --- a/app/Commands/Audit.php +++ b/app/Commands/Audit.php @@ -2,6 +2,7 @@ namespace ProjektGopher\Whisky\Commands; +use Illuminate\Support\Facades\Process; use LaravelZero\Framework\Commands\Command; use ProjektGopher\Whisky\Platform; use ProjektGopher\Whisky\Whisky; @@ -20,7 +21,7 @@ public function handle(): int ['key', 'value'], [ ['- Whisky -', ''], - ['installed globally?', Whisky::isInstalledGlobally() ? 'yes (v'.(include Platform::getGlobalComposerHome().'/vendor/projektgopher/whisky/config/app.php')['version'].')' : 'no'], + ['installed globally?', $this->isWhiskyInstalledGlobally()], ['running globally?', Whisky::isRunningGlobally() ? 'yes' : 'no'], ['dogfooding?', Whisky::dogfooding() ? 'yes' : 'no'], ['base path', Whisky::base_path()], @@ -42,4 +43,16 @@ public function handle(): int return Command::SUCCESS; } + + protected function isWhiskyInstalledGlobally(): string + { + if (! Whisky::isInstalledGlobally()) { + return 'no'; + } + + $result = Process::run('composer global show projektgopher/whisky --format=json'); + $version = json_decode($result->output(), true)['versions'][0]; + + return "yes ({$version})"; + } } From d3813c33fc02fb437edccff274f89a7353b46cf3 Mon Sep 17 00:00:00 2001 From: Len Woodward Date: Fri, 24 May 2024 11:15:35 -0700 Subject: [PATCH 4/6] add methods for local install --- app/Whisky.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/Whisky.php b/app/Whisky.php index 7e54aaf..b90d79d 100644 --- a/app/Whisky.php +++ b/app/Whisky.php @@ -41,6 +41,16 @@ public static function isRunningGlobally(): bool return str_starts_with(base_path(), 'phar://'.Platform::getGlobalComposerHome()); } + public static function isInstalledLocally(): bool + { + return File::exists(Platform::cwd('vendor/projektgopher/whisky')); + } + + public static function isRunningLocally(): bool + { + return str_starts_with(base_path(), 'phar://'.Platform::cwd('vendor/bin')); + } + public static function readConfig(string $key): string|array|null { $cfg = FileJson::make(Platform::cwd('whisky.json'))->read(); From e369914c988c48b2d9f6b7fcd70023a3e1b7bcf9 Mon Sep 17 00:00:00 2001 From: Len Woodward Date: Fri, 24 May 2024 11:15:48 -0700 Subject: [PATCH 5/6] add local install info to audit command --- app/Commands/Audit.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Commands/Audit.php b/app/Commands/Audit.php index bde1559..7eb18c1 100644 --- a/app/Commands/Audit.php +++ b/app/Commands/Audit.php @@ -23,6 +23,8 @@ public function handle(): int ['- Whisky -', ''], ['installed globally?', $this->isWhiskyInstalledGlobally()], ['running globally?', Whisky::isRunningGlobally() ? 'yes' : 'no'], + ['installed locally?', Whisky::isInstalledLocally() ? 'yes' : 'no'], + ['running locally?', Whisky::isRunningLocally() ? 'yes' : 'no'], ['dogfooding?', Whisky::dogfooding() ? 'yes' : 'no'], ['base path', Whisky::base_path()], ['bin path', Whisky::bin_path()], From a7ed47f8ff0555d3de7ba3e93ee91db10e966daf Mon Sep 17 00:00:00 2001 From: Len Woodward Date: Fri, 24 May 2024 11:18:58 -0700 Subject: [PATCH 6/6] get locally installed version number --- app/Commands/Audit.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/Commands/Audit.php b/app/Commands/Audit.php index 7eb18c1..53b9107 100644 --- a/app/Commands/Audit.php +++ b/app/Commands/Audit.php @@ -23,7 +23,7 @@ public function handle(): int ['- Whisky -', ''], ['installed globally?', $this->isWhiskyInstalledGlobally()], ['running globally?', Whisky::isRunningGlobally() ? 'yes' : 'no'], - ['installed locally?', Whisky::isInstalledLocally() ? 'yes' : 'no'], + ['installed locally?', $this->isWhiskyInstalledLocally()], ['running locally?', Whisky::isRunningLocally() ? 'yes' : 'no'], ['dogfooding?', Whisky::dogfooding() ? 'yes' : 'no'], ['base path', Whisky::base_path()], @@ -57,4 +57,16 @@ protected function isWhiskyInstalledGlobally(): string return "yes ({$version})"; } + + protected function isWhiskyInstalledLocally(): string + { + if (! Whisky::isInstalledLocally()) { + return 'no'; + } + + $result = Process::run('composer show projektgopher/whisky --format=json'); + $version = json_decode($result->output(), true)['versions'][0]; + + return "yes ({$version})"; + } }