-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #136 from ucan-lab/topic-135
Support Stub Customization
- Loading branch information
Showing
11 changed files
with
149 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace UcanLab\LaravelDacapo\Console; | ||
|
||
use Illuminate\Filesystem\Filesystem; | ||
use UcanLab\LaravelDacapo\Dacapo\UseCase\Console\DacapoUninstallCommandUseCase; | ||
|
||
/** | ||
* Class DacapoStubPublishCommand | ||
*/ | ||
class DacapoStubPublishCommand extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'dacapo:stub:publish {--force : Overwrite any existing files}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Publish dacapo stubs that are available for customization.'; | ||
|
||
/** | ||
* @var DacapoUninstallCommandUseCase | ||
*/ | ||
protected DacapoUninstallCommandUseCase $useCase; | ||
|
||
public function handle(): void | ||
{ | ||
if (!is_dir($stubsPath = $this->laravel->basePath('stubs'))) { | ||
(new Filesystem)->makeDirectory($stubsPath); | ||
} | ||
|
||
$files = [ | ||
realpath(__DIR__ . '/../Dacapo/Infra/Adapter/Stub/dacapo.migration.create.stub') => $stubsPath . '/dacapo.migration.create.stub', | ||
realpath(__DIR__ . '/../Dacapo/Infra/Adapter/Stub/dacapo.migration.update.stub') => $stubsPath . '/dacapo.migration.update.stub', | ||
]; | ||
|
||
foreach ($files as $from => $to) { | ||
if (!file_exists($to) || $this->option('force')) { | ||
file_put_contents($to, file_get_contents($from)); | ||
} | ||
} | ||
|
||
$this->info('Stubs published successfully.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace UcanLab\LaravelDacapo\Dacapo\Infra\Adapter; | ||
|
||
use UcanLab\LaravelDacapo\Dacapo\UseCase\Shared\Stub\MigrationCreateStub; | ||
|
||
class LaravelMigrationCreateStub implements MigrationCreateStub | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
public function getStub(): string | ||
{ | ||
$filename = base_path('stubs/dacapo.migration.create.stub'); | ||
|
||
if (file_exists($filename)) { | ||
return file_get_contents($filename); | ||
} | ||
|
||
return file_get_contents(__DIR__ . '/Stub/dacapo.migration.create.stub'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace UcanLab\LaravelDacapo\Dacapo\Infra\Adapter; | ||
|
||
use UcanLab\LaravelDacapo\Dacapo\UseCase\Shared\Stub\MigrationUpdateStub; | ||
|
||
class LaravelMigrationUpdateStub implements MigrationUpdateStub | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
public function getStub(): string | ||
{ | ||
$filename = app_path('stubs/dacapo.migration.update.stub'); | ||
|
||
if (file_exists($filename)) { | ||
return file_get_contents($filename); | ||
} | ||
|
||
return file_get_contents(__DIR__ . '/Stub/dacapo.migration.update.stub'); | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace UcanLab\LaravelDacapo\Dacapo\UseCase\Shared\Stub; | ||
|
||
interface MigrationCreateStub | ||
{ | ||
public function getStub(): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace UcanLab\LaravelDacapo\Dacapo\UseCase\Shared\Stub; | ||
|
||
interface MigrationUpdateStub | ||
{ | ||
public function getStub(): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters