Skip to content

Commit

Permalink
added command plugin setup
Browse files Browse the repository at this point in the history
  • Loading branch information
199ocero committed Jul 4, 2024
1 parent e465524 commit 724c1a4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
44 changes: 42 additions & 2 deletions src/Commands/FilaChatCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,57 @@
namespace JaOcero\FilaChat\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
use JaOcero\FilaChat\Enums\RoleType;
use JaOcero\FilaChat\Models\FilaChatRole;

class FilaChatCommand extends Command
{
public $signature = 'filachat';
public $signature = 'filachat::install';

public $description = 'My command';
public $description = 'Setup the FilaChat plugin';

public function handle(): int
{
$this->info('Starting FilaChat setup...');
$this->publishAssets();
$this->runMigrations();
$this->seedRoles();
$this->comment('All done');

return self::SUCCESS;
}

protected function publishAssets()
{
$this->info('Publishing assets...');
Artisan::call('vendor:publish', [
'--provider' => 'JaOcero\FilaChat\FilaChatServiceProvider',
'--tag' => ['migrations', 'config'],
]);
$this->info('Assets published.');
}

protected function runMigrations()
{
$this->info('Running migrations...');
Artisan::call('migrate');
$this->info('Migrations completed.');
}

protected function seedRoles()
{
$this->info('Seeding roles...');

$roles = [
['name' => RoleType::AGENT->value],
['name' => RoleType::USER->value],
];

foreach ($roles as $role) {
FilaChatRole::firstOrCreate($role);
}

$this->info('Roles seeded.');
}
}
6 changes: 1 addition & 5 deletions src/FilaChatServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ public function configurePackage(Package $package): void
$package->name(static::$name)
->hasCommands($this->getCommands())
->hasInstallCommand(function (InstallCommand $command) {
$command
->publishConfigFile()
->publishMigrations()
->askToRunMigrations()
->askToStarRepoOnGitHub('199ocero/filachat');
$command->askToStarRepoOnGitHub('199ocero/filachat');
});

$configFileName = $package->shortName();
Expand Down

0 comments on commit 724c1a4

Please sign in to comment.