Skip to content

Commit

Permalink
Merge pull request #747 from lee-to/page-command-with-extends-select
Browse files Browse the repository at this point in the history
feat: Make page with select
  • Loading branch information
lee-to authored Dec 29, 2023
2 parents cfefd89 + b4bd4ce commit cac6081
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
7 changes: 3 additions & 4 deletions src/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@

use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Support\Facades\File;

use function Laravel\Prompts\{confirm, intro, outro, spin, warning};

use MoonShine\MoonShine;

use MoonShine\Providers\MoonShineServiceProvider;

use function Laravel\Prompts\{confirm, intro, outro, spin, warning};

class InstallCommand extends MoonShineCommand
{
protected $signature = 'moonshine:install {--u|without-user} {--m|without-migrations}';
Expand Down Expand Up @@ -127,6 +125,7 @@ protected function initDashboard(): void
{
$this->call(MakePageCommand::class, [
'className' => 'Dashboard',
'--force' => true
]);

$this->replaceInFile(
Expand Down
38 changes: 30 additions & 8 deletions src/Commands/MakePageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
namespace MoonShine\Commands;

use Illuminate\Contracts\Filesystem\FileNotFoundException;
use MoonShine\MoonShine;

use function Laravel\Prompts\outro;

use function Laravel\Prompts\select;
use function Laravel\Prompts\text;

use MoonShine\MoonShine;

class MakePageCommand extends MoonShineCommand
{
protected $signature = 'moonshine:page {className?} {--crud} {--dir=} {--extends=}';
protected $signature = 'moonshine:page {className?} {--force} {--crud} {--dir=} {--extends=}';

protected $description = 'Create page';

Expand All @@ -33,19 +32,42 @@ public function handle(): int
$dir = $this->option('dir') ?: dirname($className);
$className = class_basename($className);

if($dir === '.') {
if ($dir === '.') {
$dir = 'Pages';
}

if (! $this->option('force') && ! $this->option('extends') && ! $this->option('crud')) {
$types = [
'' => 'Custom',
'IndexPage' => 'IndexPage',
'FormPage' => 'FormPage',
'DetailPage' => 'DetailPage',
];

$type = array_search(
select('Type', $types),
$types,
true
);

$extends = $type ?: null;

$this->makePage($className, $extends ? 'CrudPage' : 'Page', $dir, $extends);

return self::SUCCESS;
}

if ($this->option('crud')) {
$dir = "$dir/$className";
foreach (['IndexPage', 'FormPage', 'DetailPage'] as $type) {
$this->makePage($className . $type, 'CrudPage', $dir, $type);
}
} else {
$this->makePage($className, 'Page', $dir, $extends);

return self::SUCCESS;
}

$this->makePage($className, 'Page', $dir, $extends);

return self::SUCCESS;
}

Expand All @@ -59,7 +81,7 @@ private function makePage(
?string $extends = null
): void {
$dir = is_null($dir) ? 'Pages' : $dir;
$extends = is_null($extends) ? 'Page' : $extends;
$extends = empty($extends) ? 'Page' : $extends;

$page = $this->getDirectory() . "/$dir/$className.php";

Expand Down

0 comments on commit cac6081

Please sign in to comment.