Skip to content

Commit f435ea8

Browse files
authored
Merge pull request #3 from SalemC/add-typescriptify-model-command
Add typescriptify:model command
2 parents bcf4861 + e76ccff commit f435ea8

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
"require": {},
1818
"extra": {
1919
"laravel": {
20+
"providers": [
21+
"\\SalemC\\TypeScriptifyLaravelModels\\Providers\\TypeScriptifyModelsServiceProvider"
22+
],
2023
"aliases": {
2124
"TypeScriptifyModel": "SalemC\\TypeScriptifyLaravelModels\\TypeScriptifyModel"
2225
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace SalemC\TypeScriptifyLaravelModels\Commands;
4+
5+
use Illuminate\Console\Command;
6+
7+
use SalemC\TypeScriptifyLaravelModels\TypeScriptifyModel;
8+
9+
class TypeScriptifyModelCommand extends Command {
10+
/**
11+
* The name and signature of the console command.
12+
*
13+
* @var string
14+
*/
15+
protected $signature = 'typescriptify:model {model : The fully qualified class name for the model - e.g. App\Models\User}';
16+
17+
/**
18+
* The console command description.
19+
*
20+
* @var string
21+
*/
22+
protected $description = 'Convert a model to it\'s TypeScript definition.';
23+
24+
/**
25+
* Execute the console command.
26+
*
27+
* @return int
28+
*/
29+
public function handle() {
30+
echo TypeScriptifyModel::generate($this->argument('model'));
31+
32+
return Command::SUCCESS;
33+
}
34+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace SalemC\TypeScriptifyLaravelModels\Providers;
4+
5+
use Illuminate\Support\ServiceProvider;
6+
7+
use SalemC\TypeScriptifyLaravelModels\Commands\TypeScriptifyModelCommand;
8+
9+
class TypeScriptifyModelsServiceProvider extends ServiceProvider {
10+
/**
11+
* Register all commands.
12+
*
13+
* @return void
14+
*/
15+
private function registerCommands(): void {
16+
if (!$this->app->runningInConsole()) return;
17+
18+
$this->commands([
19+
TypeScriptifyModelCommand::class,
20+
]);
21+
}
22+
23+
/**
24+
* Bootstrap services.
25+
*
26+
* @return void
27+
*/
28+
public function boot(): void {
29+
$this->registerCommands();
30+
}
31+
}

0 commit comments

Comments
 (0)