Skip to content
This repository was archived by the owner on Jan 10, 2025. It is now read-only.

Commit 4af4fe0

Browse files
authored
Merge pull request #9 from Xammie/add-make-config
Add make command for config files
2 parents c3086ea + 3c3d15c commit 4af4fe0

File tree

6 files changed

+60
-1
lines changed

6 files changed

+60
-1
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@ This is the contents of the published config file:
5353
return [
5454
'namespaces' => [
5555
'action' => 'Actions',
56-
'collection' => 'Collection',
56+
'collection' => 'Collections',
57+
'config' => 'config',
5758
'contract' => 'Contracts',
5859
'dto' => 'Dtos',
5960
'enum' => 'Enums',
6061
'interface' => 'Interfaces',
6162
'repository' => 'Repositories',
6263
'service' => 'Services',
64+
'trait' => 'Traits',
6365
],
6466
];
6567
```
@@ -71,6 +73,7 @@ The following commands are available.
7173
```
7274
php artisan make:action CreateUserAction
7375
php artisan make:collection OrderCollection
76+
php artisan make:config config-file
7477
php artisan make:contract CreatesUserContract
7578
php artisan make:dto RestRequestObject
7679
php artisan make:enum OrderStatusEnum

config/make-commands.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
'namespaces' => [
1313
'action' => 'Actions',
1414
'collection' => 'Collections',
15+
'config' => 'config',
1516
'contract' => 'Contracts',
1617
'dto' => 'Dtos',
1718
'enum' => 'Enums',

src/Commands/ConfigMakeCommand.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Xammie\MakeCommands\Commands;
4+
5+
use Illuminate\Console\GeneratorCommand;
6+
use Illuminate\Support\Str;
7+
8+
class ConfigMakeCommand extends GeneratorCommand
9+
{
10+
use GeneratorTrait;
11+
12+
protected $name = 'make:config';
13+
14+
protected $description = 'Create a new config file';
15+
16+
protected $type = 'Config';
17+
18+
protected function stubName(): string
19+
{
20+
return 'config';
21+
}
22+
23+
protected function getPath($name)
24+
{
25+
$name = Str::replaceFirst($this->rootNamespace(), '', $name);
26+
27+
return str_replace('\\', '/', base_path($name)) . '.php';
28+
}
29+
30+
protected function alreadyExists($rawName): bool
31+
{
32+
return $this->files->exists($this->getPath($this->qualifyClass($rawName)));
33+
}
34+
}

src/Commands/stubs/config.stub

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
return [
4+
/*
5+
|--------------------------------------------------------------------------
6+
| {{ class }}
7+
|--------------------------------------------------------------------------
8+
|
9+
| {{ class }} description...
10+
|
11+
*/
12+
13+
'key' => env('KEY', 'value'),
14+
];

src/MakeCommandsServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Spatie\LaravelPackageTools\PackageServiceProvider;
77
use Xammie\MakeCommands\Commands\ActionMakeCommand;
88
use Xammie\MakeCommands\Commands\CollectionMakeCommand;
9+
use Xammie\MakeCommands\Commands\ConfigMakeCommand;
910
use Xammie\MakeCommands\Commands\ContractMakeCommand;
1011
use Xammie\MakeCommands\Commands\DtoMakeCommand;
1112
use Xammie\MakeCommands\Commands\EnumMakeCommand;
@@ -24,6 +25,7 @@ public function configurePackage(Package $package): void
2425
->hasCommands([
2526
ActionMakeCommand::class,
2627
CollectionMakeCommand::class,
28+
ConfigMakeCommand::class,
2729
ContractMakeCommand::class,
2830
DtoMakeCommand::class,
2931
EnumMakeCommand::class,

tests/CommandsTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use function Pest\Laravel\artisan;
44
use Xammie\MakeCommands\Commands\ActionMakeCommand;
55
use Xammie\MakeCommands\Commands\CollectionMakeCommand;
6+
use Xammie\MakeCommands\Commands\ConfigMakeCommand;
67
use Xammie\MakeCommands\Commands\ContractMakeCommand;
78
use Xammie\MakeCommands\Commands\DtoMakeCommand;
89
use Xammie\MakeCommands\Commands\EnumMakeCommand;
@@ -19,6 +20,10 @@
1920
artisan(CollectionMakeCommand::class, ['name' => 'TestCollection'])->assertExitCode(0);
2021
});
2122

23+
it('can make config', function () {
24+
artisan(ConfigMakeCommand::class, ['name' => 'test-config'])->assertExitCode(0);
25+
});
26+
2227
it('can make contract', function () {
2328
artisan(ContractMakeCommand::class, ['name' => 'TestContract'])->assertExitCode(0);
2429
});

0 commit comments

Comments
 (0)