Skip to content

Commit

Permalink
InstallPoolPackage.php updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimimo committed Apr 13, 2023
1 parent 5f5fafa commit 1317e86
Showing 1 changed file with 65 additions and 9 deletions.
74 changes: 65 additions & 9 deletions src/Commands/InstallPoolPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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?');
}
}

0 comments on commit 1317e86

Please sign in to comment.