Skip to content

Commit

Permalink
Update make:settings command signature and handle existing files
Browse files Browse the repository at this point in the history
  • Loading branch information
inerba committed Feb 6, 2024
1 parent 831f825 commit 9487c50
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions src/Commands/DbConfigCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class DbConfigCommand extends Command
{
public $signature = 'make:settings {name}';
public $signature = 'make:settings {name} {panel?}';

public $description = 'Create a new settings';

Expand Down Expand Up @@ -44,9 +44,8 @@ public function handle(): void
$this->files->put($path, $contents);
$this->info("File : {$path} created");
} else {
$this->info("File : {$path} already exits");
$this->warn("File : {$path} already exits");
}

}

/**
Expand All @@ -62,6 +61,11 @@ public function createViewFromStub(string $viewName): void
// Define the path to the new view file.
$newViewPath = resource_path('views/' . str_replace('.', '/', $viewName) . '.blade.php');

if ($this->files->exists($newViewPath)) {
$this->warn("File : {$newViewPath} already exists");
return;
}

// Read the contents of the view stub.
$viewStubContents = file_get_contents($viewStubPath);

Expand Down Expand Up @@ -94,6 +98,7 @@ public function getStubVariables(): array
{
return [
'TITLE' => $this->getSingularClassName($this->argument('name')),
'PANEL' => $this->argument('panel') ? ucfirst($this->argument('panel')) . '\\' : '',
'CLASS_NAME' => $this->getSingularClassName($this->argument('name')),
'SETTING_NAME' => str($this->argument('name'))->lower()->slug(),
];
Expand Down Expand Up @@ -123,11 +128,15 @@ public function getStubContents(string $stub, array $stubVariables = []): string
}

/**
* Get the full path of generate class
* Get the full path of the generated class.
*/
public function getSourceFilePath(): string
{
return base_path('App\\Filament\\Pages') . '\\' . $this->getSingularClassName($this->argument('name')) . 'SettingsPage.php';
$panel = $this->argument('panel');
$panelPrefix = $panel ? ucfirst($panel) . '\\' : '';

$path = base_path('app\\Filament\\' . $panelPrefix . 'Pages') . '\\' . $this->getSingularClassName($this->argument('name')) . 'SettingsPage.php';
return str_replace('\\', '/', $path);
}

/**
Expand All @@ -143,6 +152,7 @@ public function getSingularClassName($name): string
*/
protected function makeDirectory(string $path): string
{

if (! $this->files->isDirectory($path)) {
$this->files->makeDirectory($path, 0777, true, true);
}
Expand Down
2 changes: 1 addition & 1 deletion stubs/page.stub
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Filament\Pages;
namespace App\Filament\$PANEL$Pages;

use Filament\Forms\Form;
use Postare\DbConfig\AbstractPageSettings;
Expand Down

0 comments on commit 9487c50

Please sign in to comment.