Skip to content

Commit

Permalink
feat: Generate collection auto commit
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-code-labx committed Jun 6, 2024
1 parent ed71d28 commit 0338a79
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Commands/GenerateApiCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Symfony\Component\Console\Attribute\AsCommand;
use XtendPackages\RESTPresenter\Concerns\InteractsWithGit;
use XtendPackages\RESTPresenter\Support\ApiCollection\Exporters\ExporterContract;

use function Laravel\Prompts\confirm;

#[AsCommand(name: 'rest-presenter:generate-api-collection')]
final class GenerateApiCollection extends Command
{
use InteractsWithGit;

protected $signature = 'rest-presenter:generate-api-collection';

protected $description = 'Exports API collection from your applications API routes';
Expand All @@ -27,6 +32,10 @@ public function handle(): int
{
$this->info('Generating API Collection...');

if (confirm(__('Would you like to auto-commit the generated API collection?'))) {
$this->gitAutoCommit = $this->isCleanWorkingDirectory();
}

$this->exportApiCollection();

return self::SUCCESS;
Expand All @@ -45,6 +54,12 @@ private function exportApiCollection(): void
);

$this->info('API Collection Exported: '.$filePath);

if ($this->gitAutoCommit) {
$this->commitChanges(__('feat: API Collection for :exporter', [
'exporter' => type(config('rest-presenter.exporters.provider'))->asString(),
]));
}
}

private function generateFilePath(): string
Expand Down

0 comments on commit 0338a79

Please sign in to comment.