Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make commands #20

Merged
merged 4 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
]);
}
}