Skip to content

Commit 988d984

Browse files
Expand Parkman Schema to support full Laravel component generation
- Improved PrismaSchemaParser to support Enums, model/field attributes, and relations. - Implemented generation for Models, API Controllers, Services, Factories, and Seeders. - Updated Migration generation to support more Prisma features. - Added configurable output paths and namespaces in config/config.php. - Created unified parkman:generate Artisan command. - Added automated tests for all components. - Refined stubs and updated README. Co-authored-by: paulobunga <10288731+paulobunga@users.noreply.github.com>
1 parent 9a54575 commit 988d984

14 files changed

Lines changed: 758 additions & 267 deletions

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,15 @@ This will create model files in your Laravel project's `app/Models` directory.
4949
The package also provides Artisan commands for easy use:
5050

5151
```bash
52-
# Generate migrations
53-
php artisan parkman:migrations path/to/your/schema.prisma
52+
# Generate everything
53+
php artisan parkman:generate path/to/your/schema.prisma --all
5454

55-
# Generate models
56-
php artisan parkman:models path/to/your/schema.prisma
55+
# Generate specific components (migrations are generated by default if no flags)
56+
php artisan parkman:generate path/to/your/schema.prisma --models --controllers
57+
58+
# Individual commands (legacy)
59+
php artisan parkman:generate-migrations path/to/your/schema.prisma
60+
php artisan parkman:generate-models path/to/your/schema.prisma
5761
```
5862

5963
### Customizing Stubs

config/config.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
<?php
22

3-
/*
4-
* You can place your custom package configuration in here.
5-
*/
63
return [
4+
/*
5+
* Default paths for generated files.
6+
*/
7+
'paths' => [
8+
'models' => app_path('Models'),
9+
'migrations' => database_path('migrations'),
10+
'controllers' => app_path('Http/Controllers/Api'),
11+
'factories' => database_path('factories'),
12+
'seeders' => database_path('seeders'),
13+
'services' => app_path('Services'),
14+
],
715

8-
];
16+
/*
17+
* Default namespaces for generated classes.
18+
*/
19+
'namespaces' => [
20+
'models' => 'App\\Models',
21+
'controllers' => 'App\\Http\\Controllers\\Api',
22+
'services' => 'App\\Services',
23+
],
24+
];
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
namespace Paulobunga\ParkmanSchema\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use Paulobunga\ParkmanSchema\ParkmanSchema;
7+
8+
class ParkmanGenerateCommand extends Command
9+
{
10+
protected $signature = 'parkman:generate {schema : Path to the Prisma schema file}
11+
{--models : Generate models}
12+
{--controllers : Generate API controllers}
13+
{--factories : Generate factories}
14+
{--seeders : Generate seeders}
15+
{--services : Generate services}
16+
{--migrations : Generate migrations}
17+
{--all : Generate everything}';
18+
19+
protected $description = 'Generate Laravel components based on Prisma schema';
20+
21+
public function handle()
22+
{
23+
$schemaPath = $this->argument('schema');
24+
25+
if (!file_exists($schemaPath)) {
26+
$this->error("Schema file not found: {$schemaPath}");
27+
return 1;
28+
}
29+
30+
$schema = file_get_contents($schemaPath);
31+
$parkman = new ParkmanSchema($schema);
32+
33+
$generateAll = $this->option('all');
34+
35+
// Migrations are first class citizens, generate by default or if requested
36+
if ($generateAll || $this->option('migrations') || (!$this->anyOptionSet())) {
37+
$this->info('Generating migrations...');
38+
$parkman->generateMigrations();
39+
}
40+
41+
if ($generateAll || $this->option('models')) {
42+
$this->info('Generating models...');
43+
$parkman->generateModels();
44+
}
45+
46+
if ($generateAll || $this->option('controllers')) {
47+
$this->info('Generating controllers...');
48+
$parkman->generateControllers();
49+
}
50+
51+
if ($generateAll || $this->option('services')) {
52+
$this->info('Generating services...');
53+
$parkman->generateServices();
54+
}
55+
56+
if ($generateAll || $this->option('factories')) {
57+
$this->info('Generating factories...');
58+
$parkman->generateFactories();
59+
}
60+
61+
if ($generateAll || $this->option('seeders')) {
62+
$this->info('Generating seeders...');
63+
$parkman->generateSeeders();
64+
}
65+
66+
$this->info('Generation completed successfully.');
67+
}
68+
69+
protected function anyOptionSet()
70+
{
71+
return $this->option('models') ||
72+
$this->option('controllers') ||
73+
$this->option('factories') ||
74+
$this->option('seeders') ||
75+
$this->option('services') ||
76+
$this->option('migrations');
77+
}
78+
}

0 commit comments

Comments
 (0)