From d416b1c637170e4e2d6c37ca3fb897921ea45da7 Mon Sep 17 00:00:00 2001 From: Samuel De Backer Date: Wed, 1 Nov 2023 22:06:20 +0100 Subject: [PATCH] Update Publish.php --- src/Commands/Publish.php | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/src/Commands/Publish.php b/src/Commands/Publish.php index de6dc677..aa7b4e83 100644 --- a/src/Commands/Publish.php +++ b/src/Commands/Publish.php @@ -11,6 +11,9 @@ use League\Flysystem\MountManager; use League\Flysystem\UnixVisibility\PortableVisibilityConverter; use League\Flysystem\Visibility; +use function Laravel\Prompts\error; +use function Laravel\Prompts\info; +use function Laravel\Prompts\spin; class Publish extends Command { @@ -56,7 +59,7 @@ public function __construct(Filesystem $files) /** * Execute the console command. */ - public function handle() + public function handle(): void { $this->module = mb_strtolower($this->argument('module')); if (!is_dir(base_path('vendor/typicms/' . $this->module))) { @@ -68,6 +71,7 @@ public function handle() $this->publishModule(); $this->changePathForLoadViews(); $this->uninstallFromComposer(); + info(ucfirst($this->module) . ' module successfully published.'); } else { throw new Exception($provider . ' not found, did you add it to config/app.php?'); } @@ -86,10 +90,8 @@ private function publishModule() if ($this->files->isDirectory($from)) { $this->publishDirectory($from, $to); } else { - $this->error("Can’t locate path: <{$from}>"); + error("Can’t locate path: <{$from}>"); } - - $this->info('Publishing complete for module [' . ucfirst($this->module) . ']!'); } /** @@ -116,24 +118,6 @@ protected function publishDirectory($from, $to) $manager->write('to://' . $path, $manager->read($file['path'])); } } - - $this->status($from, $to, 'Directory'); - } - - /** - * Write a status message to the console. - * - * @param string $from - * @param string $to - * @param string $type - */ - protected function status($from, $to, $type) - { - $from = str_replace(base_path(), '', realpath($from)); - - $to = str_replace(base_path(), '', realpath($to)); - - $this->line('Copied ' . $type . ' [' . $from . '] To [' . $to . ']'); } /** @@ -152,11 +136,14 @@ private function changePathForLoadViews() */ private function uninstallFromComposer() { - $uninstallCommand = 'composer remove typicms/' . $this->module; - if (function_exists('system')) { - system($uninstallCommand); + if (is_callable('shell_exec') && !stripos(ini_get('disable_functions'), 'shell_exec')) { + $uninstallCommand = 'composer remove typicms/' . $this->module . ' 2> /dev/null'; + spin( + fn () => shell_exec($uninstallCommand), + 'Uninstall ' . $this->module . ' from composer…' + ); } else { - $this->line('You can now run ' . $uninstallCommand . '.'); + info('You can now run ' . $uninstallCommand . '.'); } } }