From 1317e860d89c8b79a4f1d97c347073c7c70e5a8f Mon Sep 17 00:00:00 2001 From: Dimitri Mostrey Date: Thu, 13 Apr 2023 12:38:00 +0800 Subject: [PATCH] InstallPoolPackage.php updated --- src/Commands/InstallPoolPackage.php | 74 +++++++++++++++++++++++++---- 1 file changed, 65 insertions(+), 9 deletions(-) diff --git a/src/Commands/InstallPoolPackage.php b/src/Commands/InstallPoolPackage.php index 1a09b0c..0ec439e 100644 --- a/src/Commands/InstallPoolPackage.php +++ b/src/Commands/InstallPoolPackage.php @@ -14,31 +14,77 @@ class InstallPoolPackage extends Command public function handle() { $this->info('Installing the Pool Package...'); + + $this->configInstallation(); + $this->viewsInstallation(); + $this->assetsInstallation(); + $this->migrationsInstallation(); + + $this->info('The Pool Package is installed. Enjoy!'); + } + + private function configInstallation() + { $this->info('Publishing configuration...'); - if (! $this->configExists()) { - $this->publishConfiguration(); + if (! File::exists(config_path('pool.php'))) { + $this->publishTags('config'); $this->info('Published configuration'); } else { if ($this->shouldOverwriteConfig()) { $this->info('Overwriting configuration file...'); - $this->publishConfiguration(true); + $this->publishTags('config', true); } else { $this->info('Existing configuration was not overwritten'); } } - $this->info('Installed Pool Package'); } - private function configExists(): bool + private function viewsInstallation() + { + $this->info('Publishing views...'); + if (! File::isDirectory(resource_path('views/vendor/pool'))) { + $this->publishTags('views'); + $this->info('Published views'); + } else { + if ($this->shouldOverwriteViews()) { + $this->info('Overwriting view files...'); + $this->publishTags('views', true); + } else { + $this->info('Existing views were not overwritten'); + } + } + } + + private function assetsInstallation() + { + $this->info('Publishing assets...'); + if (! File::exists(public_path('js/pool.js'))) { + $this->publishTags('assets'); + $this->info('Published assets on public/js'); + } else { + if ($this->shouldOverwriteAssets()) { + $this->info('Overwriting asset files...'); + $this->publishTags('assets', true); + } else { + $this->info('Existing asset files were not overwritten'); + } + } + } + + private function migrationsInstallation() { - return File::exists(config_path('pool.php')); + if (! class_exists('CreatePoolAdminsTable')) { + $this->info('Publishing migrations...'); + $this->publishTags('migrations'); + $this->info('Migrations are published'); + } } - private function publishConfiguration($force = false) + private function publishTags($tag, $force = false) { $params = [ '--provider' => "Dimimo\Pool\PoolServiceProvider", - '--tag' => 'config', + '--tag' => $tag, ]; if ($force === true) { $params['--force'] = true; @@ -48,6 +94,16 @@ private function publishConfiguration($force = false) private function shouldOverwriteConfig(): bool { - return $this->confirm('Config file already exists. Do you want to overwrite it?'); + return $this->confirm('Config file pool.php already exists. Do you want to overwrite it?'); + } + + private function shouldOverwriteViews(): bool + { + return $this->confirm('The resources views already exists. Do you want to overwrite them?'); + } + + private function shouldOverwriteAssets(): bool + { + return $this->confirm('The asset files (public/js) already exists. Do you want to overwrite them?'); } }