From 5de05376d82d3215000c802b10b80bf1d95eb177 Mon Sep 17 00:00:00 2001 From: RedFreak_ Date: Wed, 6 Nov 2024 21:25:12 +0100 Subject: [PATCH 1/3] added output-file argument to command by default it exports to './resources/js/types/models.d.ts' --- src/Commands/ModelTyperCommand.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Commands/ModelTyperCommand.php b/src/Commands/ModelTyperCommand.php index 560d4c9..e48be15 100644 --- a/src/Commands/ModelTyperCommand.php +++ b/src/Commands/ModelTyperCommand.php @@ -23,6 +23,7 @@ class ModelTyperCommand extends Command * @var string */ protected $signature = 'model:typer + {output-file=./resources/js/types/models.d.ts : Echo the definitions into a file} {--model= : Generate typescript interfaces for a specific model} {--global : Generate typescript interfaces in a global namespace named models} {--json : Output the result as json} @@ -62,7 +63,8 @@ public function __construct() public function handle(Generator $generator): int { try { - $this->line($generator( + $path = $this->argument('output-file'); + $output = $generator( $this->option('model'), $this->option('global'), $this->option('json'), @@ -77,7 +79,14 @@ public function handle(Generator $generator): int $this->option('resolve-abstract'), $this->option('fillables'), $this->option('fillable-suffix') - )); + ); + + if ($path) { + $this->files->ensureDirectoryExists(dirname($path)); + $this->files->put($path, $output); + } + + $this->line($output); } catch (ModelTyperException $exception) { $this->error($exception->getMessage()); From 7002a519bf626f2d486261c47ced07a2189d6061 Mon Sep 17 00:00:00 2001 From: RedFreak_ Date: Wed, 6 Nov 2024 21:32:51 +0100 Subject: [PATCH 2/3] added file-system added file-system --- src/Commands/ModelTyperCommand.php | 12 +++++++++++- src/ModelTyperServiceProvider.php | 4 ++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Commands/ModelTyperCommand.php b/src/Commands/ModelTyperCommand.php index e48be15..a47be23 100644 --- a/src/Commands/ModelTyperCommand.php +++ b/src/Commands/ModelTyperCommand.php @@ -5,6 +5,7 @@ use FumeApp\ModelTyper\Actions\Generator; use FumeApp\ModelTyper\Exceptions\ModelTyperException; use Illuminate\Console\Command; +use Illuminate\Filesystem\Filesystem; use Symfony\Component\Console\Attribute\AsCommand; #[AsCommand(name: 'model:typer')] @@ -17,6 +18,13 @@ class ModelTyperCommand extends Command */ protected $name = 'model:typer'; + /** + * Facade for Filesystem-Access + * + * @var Filesystem + */ + protected $files; + /** * The name and signature of the console command. * @@ -52,9 +60,11 @@ class ModelTyperCommand extends Command * * @return void */ - public function __construct() + public function __construct(Filesystem $files) { parent::__construct(); + + $this->files = $files; } /** diff --git a/src/ModelTyperServiceProvider.php b/src/ModelTyperServiceProvider.php index b3dd89d..62fb3c5 100644 --- a/src/ModelTyperServiceProvider.php +++ b/src/ModelTyperServiceProvider.php @@ -23,6 +23,10 @@ public function boot(): void ShowModelCommand::class, ]); } + + $this->app->singleton(ModelTyperCommand::class, function ($app) { + return new ModelTyperCommand($app['files']); + }); } /** From 3b6f46641f22e432fab83b242505fa612a06a37e Mon Sep 17 00:00:00 2001 From: RedFreak_ Date: Wed, 6 Nov 2024 21:49:46 +0100 Subject: [PATCH 3/3] anotated the new argument in the readme.md --- readme.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/readme.md b/readme.md index ba55d9b..a0f9f26 100644 --- a/readme.md +++ b/readme.md @@ -98,6 +98,12 @@ public function getFirstNameAttribute(): string // <- this } ``` +### Optional Arguments + +``` +output-file=./resources/js/types/models.d.ts : Echo the definitions into a file +``` + ### Additional Options ```