Skip to content

Commit

Permalink
Merge pull request #20 from envor/main
Browse files Browse the repository at this point in the history
Make commands
  • Loading branch information
inmanturbo authored Mar 22, 2024
2 parents 21d3b8b + 8ea52dd commit ecfeb44
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to `one-app` will be documented in this file.

## v1.0.17 - 2024-03-14

### What's Changed

* copy hidden files too by @inmanturbo in https://github.com/envor/one-app/pull/19

**Full Changelog**: https://github.com/envor/one-app/compare/v1.0.16...v1.0.17

## v1.0.16 - 2024-03-14

### What's Changed
Expand Down
32 changes: 32 additions & 0 deletions src/Commands/FolioMakeCommand.php
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'],
];
}
}
49 changes: 49 additions & 0 deletions src/Commands/HasStubOption.php
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,
};
}
}
32 changes: 32 additions & 0 deletions src/Commands/VoltMakeCommand.php
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'],
];
}
}
4 changes: 4 additions & 0 deletions src/OneAppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace Envor\OneApp;

use Envor\OneApp\Commands\FolioMakeCommand;
use Envor\OneApp\Commands\InvitationOnlyCommand;
use Envor\OneApp\Commands\NavigationCommand;
use Envor\OneApp\Commands\OneAppCommand;
use Envor\OneApp\Commands\PassportCommand;
use Envor\OneApp\Commands\VoltMakeCommand;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;

Expand All @@ -25,6 +27,8 @@ public function configurePackage(Package $package): void
PassportCommand::class,
InvitationOnlyCommand::class,
NavigationCommand::class,
VoltMakeCommand::class,
FolioMakeCommand::class,
]);
}
}

0 comments on commit ecfeb44

Please sign in to comment.