generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 2
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 #20 from envor/main
Make commands
- Loading branch information
Showing
5 changed files
with
125 additions
and
0 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
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,32 @@ | ||
<?php | ||
|
||
namespace Envor\OneApp\Commands; | ||
|
||
use Livewire\Volt\Console\MakeCommand; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Input\InputOption; | ||
|
||
#[AsCommand(name: 'one-app:make-folio')] | ||
class FolioMakeCommand extends MakeCommand | ||
{ | ||
use HasStubOption; | ||
|
||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'one-app:make-folio'; | ||
|
||
/** | ||
* Get the console command arguments. | ||
*/ | ||
protected function getOptions(): array | ||
{ | ||
return [ | ||
['class', null, InputOption::VALUE_NONE, 'Create a class based component'], | ||
['force', 'f', InputOption::VALUE_NONE, 'Create the Volt component even if the component already exists'], | ||
['stub', 's', InputOption::VALUE_OPTIONAL, 'The stub file to use'], | ||
]; | ||
} | ||
} |
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,49 @@ | ||
<?php | ||
|
||
namespace Envor\OneApp\Commands; | ||
|
||
use function Illuminate\Filesystem\join_paths; | ||
|
||
trait HasStubOption | ||
{ | ||
/** | ||
* Get the console command arguments. | ||
*/ | ||
abstract protected function getOptions(): array; | ||
|
||
/** | ||
* Build the class with the given name. | ||
* | ||
* @param string $name | ||
* @return string | ||
* | ||
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException | ||
*/ | ||
#[\Override] | ||
protected function buildClass($name) | ||
{ | ||
$stub = $this->files->get($this->getStubOption() ?? $this->getStub()); | ||
|
||
return $this->replaceNamespace($stub, $name)->replaceClass($stub, $name); | ||
} | ||
|
||
/** | ||
* Get a stub file for the generator from a stub option. | ||
* | ||
* @return string|null | ||
*/ | ||
protected function getStubOption() | ||
{ | ||
if (! $this->hasOption('stub') || ! $this->option('stub')) { | ||
return null; | ||
} | ||
|
||
$stub = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, trim($this->option('stub'))); | ||
|
||
return match (true) { | ||
file_exists($namedStub = $this->laravel->basePath(join_paths('stubs', $stub.'.stub'))) => $namedStub, | ||
file_exists($stubPath = $stub) => $stubPath, | ||
default => null, | ||
}; | ||
} | ||
} |
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,32 @@ | ||
<?php | ||
|
||
namespace Envor\OneApp\Commands; | ||
|
||
use Livewire\Volt\Console\MakeCommand; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Input\InputOption; | ||
|
||
#[AsCommand(name: 'one-app:make-volt')] | ||
class VoltMakeCommand extends MakeCommand | ||
{ | ||
use HasStubOption; | ||
|
||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'one-app:make-volt'; | ||
|
||
/** | ||
* Get the console command arguments. | ||
*/ | ||
protected function getOptions(): array | ||
{ | ||
return [ | ||
['class', null, InputOption::VALUE_NONE, 'Create a class based component'], | ||
['force', 'f', InputOption::VALUE_NONE, 'Create the Volt component even if the component already exists'], | ||
['stub', 's', InputOption::VALUE_OPTIONAL, 'The stub file to use'], | ||
]; | ||
} | ||
} |
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