diff --git a/CHANGELOG.md b/CHANGELOG.md index 9afe111..098327b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ This changelog consists the bug & security fixes and new features being included in the releases listed below. +## **v2.0.0(23rd of September, 2024)** - _Release_ + +- [compatibility] Compatibility for Krayin v2.0.0. + +- [feature] If no arguments are passed, it will prompt for the required argument. + ## **v1.0.0 (27th of September, 2024)** - _Release_ - [feature] Create package with a single command. diff --git a/README.md b/README.md index ae95863..8ae3866 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ It packs in lots of demanding features that allows your business to scale in no ## 2. Requirements -* **Krayin**: v1.0.x +* **Krayin**: v2.0.x ## 3. Installation @@ -28,7 +28,7 @@ composer require krayin/krayin-package-generator After setting up, you will see that there are list of package commands which help you to make your package creation smooth. -Below are the list of commands, +Below are the list of commands, If no arguments are passed, it will prompt for the required argument. | S. No. | Commands | Info | Required Arguments | Optional Arguments | | :----- | :------------------------------------- | :-------------------------------------------------------------------------------------------------------------- | :------------------------------------- | :------------------ | diff --git a/src/Console/Command/CommandMakeCommand.php b/src/Console/Command/CommandMakeCommand.php index 6d5921b..03b8614 100644 --- a/src/Console/Command/CommandMakeCommand.php +++ b/src/Console/Command/CommandMakeCommand.php @@ -2,6 +2,9 @@ namespace Webkul\PackageGenerator\Console\Command; +use Symfony\Component\Console\Attribute\AsCommand; + +#[AsCommand(name: 'package:make-command')] class CommandMakeCommand extends MakeCommand { /** @@ -12,38 +15,45 @@ class CommandMakeCommand extends MakeCommand protected $signature = 'package:make-command {name} {package} {--force}'; /** - * The console command description. + * The type of class being generated. * * @var string */ + protected $type = 'Console command'; + + /** + * The console command description. + * + * @var string|null + */ protected $description = 'Create a new command.'; /** - * @return mixed + * Get the stub file for the generator. */ - protected function getStubContents() + protected function getStubContents(): string { return $this->packageGenerator->getStubContents('command', $this->getStubVariables()); } /** - * @return array + * Get the stub variables. */ - protected function getStubVariables() + protected function getStubVariables(): array { return [ - 'NAMESPACE' => $this->getClassNamespace($this->argument('package') . '/Console/Commands'), + 'NAMESPACE' => $this->getClassNamespace($this->argument('package').'/Console/Commands'), 'CLASS' => $this->getClassName(), ]; } /** - * @return string + * Get the source file path. */ - protected function getSourceFilePath() + protected function getSourceFilePath(): string { - $path = base_path('packages/' . $this->argument('package')) . '/src/Console/Commands'; + $path = base_path('packages/'.$this->argument('package')).'/src/Console/Commands'; - return $path . '/' . $this->getClassName() . '.php'; + return "$path/{$this->getClassName()}.php"; } -} \ No newline at end of file +} diff --git a/src/Console/Command/ControllerMakeCommand.php b/src/Console/Command/ControllerMakeCommand.php index a7010ff..85380f4 100644 --- a/src/Console/Command/ControllerMakeCommand.php +++ b/src/Console/Command/ControllerMakeCommand.php @@ -2,8 +2,9 @@ namespace Webkul\PackageGenerator\Console\Command; -use Webkul\PackageGenerator\Generators\PackageGenerator; +use Symfony\Component\Console\Attribute\AsCommand; +#[AsCommand(name: 'package:make-controller')] class ControllerMakeCommand extends MakeCommand { /** @@ -14,39 +15,46 @@ class ControllerMakeCommand extends MakeCommand protected $signature = 'package:make-controller {name} {package} {--force}'; /** - * The console command description. + * The type of class being generated. * * @var string */ + protected $type = 'Controller'; + + /** + * The console command description. + * + * @var string|null + */ protected $description = 'Create a new controller.'; /** - * @return mixed + * Get the stub file for the generator. */ - protected function getStubContents() + protected function getStubContents(): string { return $this->packageGenerator->getStubContents('controller', $this->getStubVariables()); } /** - * @return array + * Get the stub variables. */ - protected function getStubVariables() + protected function getStubVariables(): array { return [ - 'NAMESPACE' => $this->getClassNamespace($this->argument('package') . '/Http/Controllers'), + 'NAMESPACE' => $this->getClassNamespace($this->argument('package').'/Http/Controllers'), 'CLASS' => $this->getClassName(), 'LOWER_NAME' => $this->getLowerName(), ]; } /** - * @return string + * Get the source file path. */ - protected function getSourceFilePath() + protected function getSourceFilePath(): string { - $path = base_path('packages/' . $this->argument('package')) . '/src/Http/Controllers'; + $path = base_path('packages/'.$this->argument('package')).'/src/Http/Controllers'; - return $path . '/' . $this->getClassName() . '.php'; + return "$path/{$this->getClassName()}.php"; } -} \ No newline at end of file +} diff --git a/src/Console/Command/DatagridMakeCommand.php b/src/Console/Command/DatagridMakeCommand.php index 1f3f1f8..d17a4c0 100644 --- a/src/Console/Command/DatagridMakeCommand.php +++ b/src/Console/Command/DatagridMakeCommand.php @@ -2,6 +2,9 @@ namespace Webkul\PackageGenerator\Console\Command; +use Symfony\Component\Console\Attribute\AsCommand; + +#[AsCommand(name: 'package:make-datagrid')] class DatagridMakeCommand extends MakeCommand { /** @@ -11,6 +14,13 @@ class DatagridMakeCommand extends MakeCommand */ protected $signature = 'package:make-datagrid {name} {package} {--force}'; + /** + * The type of class being generated. + * + * @var string + */ + protected $type = 'Datagrid'; + /** * The console command description. * @@ -19,31 +29,31 @@ class DatagridMakeCommand extends MakeCommand protected $description = 'Create a new datagrid.'; /** - * @return mixed + * Get the stub file for the generator. */ - protected function getStubContents() + protected function getStubContents(): string { return $this->packageGenerator->getStubContents('datagrid', $this->getStubVariables()); } /** - * @return array + * Get the stub variables. */ - protected function getStubVariables() + protected function getStubVariables(): array { return [ - 'NAMESPACE' => $this->getClassNamespace($this->argument('package') . '/Datagrids'), + 'NAMESPACE' => $this->getClassNamespace($this->argument('package').'/DataGrids'), 'CLASS' => $this->getClassName(), ]; } /** - * @return string + * Get the source file path. */ - protected function getSourceFilePath() + protected function getSourceFilePath(): string { - $path = base_path('packages/' . $this->argument('package')) . '/src/Datagrids'; + $path = base_path('packages/'.$this->argument('package')).'/src/DataGrids'; - return $path . '/' . $this->getClassName() . '.php'; + return "$path/{$this->getClassName()}.php"; } -} \ No newline at end of file +} diff --git a/src/Console/Command/EventMakeCommand.php b/src/Console/Command/EventMakeCommand.php index b14fb49..5029151 100644 --- a/src/Console/Command/EventMakeCommand.php +++ b/src/Console/Command/EventMakeCommand.php @@ -2,6 +2,9 @@ namespace Webkul\PackageGenerator\Console\Command; +use Symfony\Component\Console\Attribute\AsCommand; + +#[AsCommand(name: 'package:make-event')] class EventMakeCommand extends MakeCommand { /** @@ -11,6 +14,13 @@ class EventMakeCommand extends MakeCommand */ protected $signature = 'package:make-event {name} {package} {--force}'; + /** + * The type of class being generated. + * + * @var string + */ + protected $type = 'Event'; + /** * The console command description. * @@ -19,31 +29,31 @@ class EventMakeCommand extends MakeCommand protected $description = 'Create a new event.'; /** - * @return mixed + * Get the stub file for the generator. */ - protected function getStubContents() + protected function getStubContents(): string { return $this->packageGenerator->getStubContents('event', $this->getStubVariables()); } /** - * @return array + * Get the stub variables. */ - protected function getStubVariables() + protected function getStubVariables(): array { return [ - 'NAMESPACE' => $this->getClassNamespace($this->argument('package') . '/Events'), + 'NAMESPACE' => $this->getClassNamespace($this->argument('package').'/Events'), 'CLASS' => $this->getClassName(), ]; } /** - * @return string + * Get the source file path. */ - protected function getSourceFilePath() + protected function getSourceFilePath(): string { - $path = base_path('packages/' . $this->argument('package')) . '/src/Events'; + $path = base_path('packages/'.$this->argument('package')).'/src/Events'; - return $path . '/' . $this->getClassName() . '.php'; + return "$path/{$this->getClassName()}.php"; } -} \ No newline at end of file +} diff --git a/src/Console/Command/ListenerMakeCommand.php b/src/Console/Command/ListenerMakeCommand.php index 1c9679b..3016ce2 100644 --- a/src/Console/Command/ListenerMakeCommand.php +++ b/src/Console/Command/ListenerMakeCommand.php @@ -2,6 +2,9 @@ namespace Webkul\PackageGenerator\Console\Command; +use Symfony\Component\Console\Attribute\AsCommand; + +#[AsCommand(name: 'package:make-listener')] class ListenerMakeCommand extends MakeCommand { /** @@ -11,6 +14,13 @@ class ListenerMakeCommand extends MakeCommand */ protected $signature = 'package:make-listener {name} {package} {--force}'; + /** + * The type of class being generated. + * + * @var string + */ + protected $type = 'Listener'; + /** * The console command description. * @@ -19,31 +29,31 @@ class ListenerMakeCommand extends MakeCommand protected $description = 'Create a new listener.'; /** - * @return mixed + * Get the stub file for the generator. */ - protected function getStubContents() + protected function getStubContents(): string { return $this->packageGenerator->getStubContents('listener', $this->getStubVariables()); } /** - * @return array + * Get the stub variables. */ - protected function getStubVariables() + protected function getStubVariables(): array { return [ - 'NAMESPACE' => $this->getClassNamespace($this->argument('package') . '/Listeners'), + 'NAMESPACE' => $this->getClassNamespace($this->argument('package').'/Listeners'), 'CLASS' => $this->getClassName(), ]; } /** - * @return string + * Get the source file path. */ - protected function getSourceFilePath() + protected function getSourceFilePath(): string { - $path = base_path('packages/' . $this->argument('package')) . '/src/Listeners'; + $path = base_path('packages/'.$this->argument('package')).'/src/Listeners'; - return $path . '/' . $this->getClassName() . '.php'; + return "$path/{$this->getClassName()}.php"; } -} \ No newline at end of file +} diff --git a/src/Console/Command/MailMakeCommand.php b/src/Console/Command/MailMakeCommand.php index 1b9c508..71e0375 100644 --- a/src/Console/Command/MailMakeCommand.php +++ b/src/Console/Command/MailMakeCommand.php @@ -2,6 +2,9 @@ namespace Webkul\PackageGenerator\Console\Command; +use Symfony\Component\Console\Attribute\AsCommand; + +#[AsCommand(name: 'package:make-mail')] class MailMakeCommand extends MakeCommand { /** @@ -11,6 +14,13 @@ class MailMakeCommand extends MakeCommand */ protected $signature = 'package:make-mail {name} {package} {--force}'; + /** + * The type of class being generated. + * + * @var string + */ + protected $type = 'Mailable'; + /** * The console command description. * @@ -19,31 +29,32 @@ class MailMakeCommand extends MakeCommand protected $description = 'Create a new mail.'; /** - * @return mixed + * Get the stub file for the generator. */ - protected function getStubContents() + protected function getStubContents(): string { return $this->packageGenerator->getStubContents('mail', $this->getStubVariables()); } /** - * @return array + * Get the stub variables. */ - protected function getStubVariables() + protected function getStubVariables(): array { return [ - 'NAMESPACE' => $this->getClassNamespace($this->argument('package') . '/Mail'), - 'CLASS' => $this->getClassName(), + 'NAMESPACE' => $this->getClassNamespace($this->argument('package').'/Mails'), + 'CLASS' => $this->getClassName(), + 'LOWER_NAME' => $this->getLowerName(), ]; } /** - * @return string + * Get the source file path. */ - protected function getSourceFilePath() + protected function getSourceFilePath(): string { - $path = base_path('packages/' . $this->argument('package')) . '/src/Mail'; + $path = base_path('packages/'.$this->argument('package')).'/src/Mails'; - return $path . '/' . $this->getClassName() . '.php'; + return "$path/{$this->getClassName()}.php"; } -} \ No newline at end of file +} diff --git a/src/Console/Command/MakeCommand.php b/src/Console/Command/MakeCommand.php index 661a17a..662b7c4 100644 --- a/src/Console/Command/MakeCommand.php +++ b/src/Console/Command/MakeCommand.php @@ -3,45 +3,35 @@ namespace Webkul\PackageGenerator\Console\Command; use Illuminate\Console\Command; +use Illuminate\Contracts\Console\PromptsForMissingInput; use Illuminate\Filesystem\Filesystem; -use Illuminate\Support\Str; use Webkul\PackageGenerator\Generators\PackageGenerator; -class MakeCommand extends Command +class MakeCommand extends Command implements PromptsForMissingInput { /** - * Filesystem object + * The type of class being generated. * - * @var \Illuminate\Filesystem\Filesystem + * @var string */ - protected $filesystem; - - /** - * PackageGenerator object - * - * @var \Webkul\PackageGenerator\Generators\PackageGenerator - */ - protected $packageGenerator; + protected $type; /** * Create a new command instance. * - * @param \Illuminate\Filesystem\Filesystem $filesystem - * @param \Webkul\PackageGenerator\Generators\PackageGenerator $packageGenerator * @return void */ public function __construct( - Filesystem $filesystem, - PackageGenerator $packageGenerator - ) - { + protected Filesystem $filesystem, + protected PackageGenerator $packageGenerator + ) { + parent::__construct(); + $this->filesystem = $filesystem; $this->packageGenerator = $packageGenerator; - - parent::__construct(); } - + /** * Execute the console command. */ @@ -61,47 +51,77 @@ public function handle() if ($this->option('force')) { $this->filesystem->put($path, $contents); } else { - $this->error("File : {$path} already exists."); + $this->components->error(sprintf('%s [%s] already exists.', $this->type, $path)); return; } } - $this->info("File Created : {$path}"); + $this->components->info(sprintf('%s [%s] created successfully.', $this->type, $path)); } /** * Get name in studly case. - * - * @return string */ - public function getStudlyName() + public function getStudlyName(): string { return class_basename($this->argument('package')); } /** - * @return string + * Get name in lower case. */ - protected function getLowerName() + protected function getLowerName(): string { - return strtolower(class_basename($this->argument('package'))); + return strtolower($this->getStudlyName()); } /** - * @return string + * Get the class name. */ - protected function getClassName() + protected function getClassName(): string { return class_basename($this->argument('name')); } /** - * @param string $name - * @return string + * Get the class namespace. */ - protected function getClassNamespace($name) + protected function getClassNamespace(string $name): array|string { return str_replace('/', '\\', $name); } -} \ No newline at end of file + + /** + * Prompt for missing input arguments using the returned questions. + */ + protected function promptForMissingArgumentsUsing(): array + { + return [ + 'name' => [ + 'What should the '.strtolower($this->type).' be named?', + match ($this->type) { + 'Console command' => 'E.g. SendEmails', + 'Controller' => 'E.g. UserController', + 'Datagrid' => 'E.g. ProductDatagrid', + 'Event' => 'E.g. PodcastProcessed', + 'Listener' => 'E.g. SendPodcastNotification', + 'Mailable' => 'E.g. OrderShipped', + 'Middleware' => 'E.g. EnsureTokenIsValid', + 'Migration' => 'E.g. create_flights_table', + 'Model' => 'E.g. Flight', + 'Model Proxy' => 'E.g. FlightProxy', + 'Contract' => 'E.g. Flight', + 'Module Provider' => 'E.g. ModuleServiceProvider', + 'Provider' => 'E.g. ElasticServiceProvider', + 'Notification' => 'E.g. InvoicePaid', + 'Repository' => 'E.g. UserRepository', + 'Request' => 'E.g. StorePodcastRequest', + 'Route' => 'E.g. web', + 'Seeder' => 'E.g. UserSeeder', + default => '', + }, + ], + ]; + } +} diff --git a/src/Console/Command/MiddlewareMakeCommand.php b/src/Console/Command/MiddlewareMakeCommand.php index 1c6f098..f701e4a 100644 --- a/src/Console/Command/MiddlewareMakeCommand.php +++ b/src/Console/Command/MiddlewareMakeCommand.php @@ -2,6 +2,9 @@ namespace Webkul\PackageGenerator\Console\Command; +use Symfony\Component\Console\Attribute\AsCommand; + +#[AsCommand(name: 'package:make-middleware')] class MiddlewareMakeCommand extends MakeCommand { /** @@ -11,6 +14,13 @@ class MiddlewareMakeCommand extends MakeCommand */ protected $signature = 'package:make-middleware {name} {package} {--force}'; + /** + * The type of class being generated. + * + * @var string + */ + protected $type = 'Middleware'; + /** * The console command description. * @@ -19,31 +29,31 @@ class MiddlewareMakeCommand extends MakeCommand protected $description = 'Create a new middleware.'; /** - * @return mixed + * Get the stub file for the generator. */ - protected function getStubContents() + protected function getStubContents(): string { return $this->packageGenerator->getStubContents('middleware', $this->getStubVariables()); } /** - * @return array + * Get the stub variables. */ - protected function getStubVariables() + protected function getStubVariables(): array { return [ - 'NAMESPACE' => $this->getClassNamespace($this->argument('package') . '/Http/Middleware'), + 'NAMESPACE' => $this->getClassNamespace($this->argument('package').'/Http/Middleware'), 'CLASS' => $this->getClassName(), ]; } /** - * @return string + * Get the source file path. */ - protected function getSourceFilePath() + protected function getSourceFilePath(): string { - $path = base_path('packages/' . $this->argument('package')) . '/src/Http/Middleware'; + $path = base_path('packages/'.$this->argument('package')).'/src/Http/Middleware'; - return $path . '/' . $this->getClassName() . '.php'; + return "$path/{$this->getClassName()}.php"; } -} \ No newline at end of file +} diff --git a/src/Console/Command/MigrationMakeCommand.php b/src/Console/Command/MigrationMakeCommand.php index 1b0ad37..f9a22f9 100644 --- a/src/Console/Command/MigrationMakeCommand.php +++ b/src/Console/Command/MigrationMakeCommand.php @@ -2,6 +2,9 @@ namespace Webkul\PackageGenerator\Console\Command; +use Symfony\Component\Console\Attribute\AsCommand; + +#[AsCommand(name: 'package:make-migration')] class MigrationMakeCommand extends MakeCommand { /** @@ -11,21 +14,28 @@ class MigrationMakeCommand extends MakeCommand */ protected $signature = 'package:make-migration {name} {package}'; + /** + * The type of class being generated. + * + * @var string + */ + protected $type = 'Migration'; + /** * The console command description. * * @var string */ protected $description = 'Create a new migration.'; - + /** * Execute the console command. */ public function handle() { $this->call('make:migration', [ - 'name' => $this->argument('name'), - '--path' => 'packages/' . $this->argument('package') . '/src/Database/Migrations', + 'name' => $this->argument('name'), + '--path' => 'packages/'.$this->argument('package').'/src/Database/Migrations', ]); } -} \ No newline at end of file +} diff --git a/src/Console/Command/ModelContractMakeCommand.php b/src/Console/Command/ModelContractMakeCommand.php index adc4be0..1d131ec 100644 --- a/src/Console/Command/ModelContractMakeCommand.php +++ b/src/Console/Command/ModelContractMakeCommand.php @@ -2,6 +2,9 @@ namespace Webkul\PackageGenerator\Console\Command; +use Symfony\Component\Console\Attribute\AsCommand; + +#[AsCommand(name: 'package:make-model-contract')] class ModelContractMakeCommand extends MakeCommand { /** @@ -11,6 +14,13 @@ class ModelContractMakeCommand extends MakeCommand */ protected $signature = 'package:make-model-contract {name} {package} {--force}'; + /** + * The type of class being generated. + * + * @var string + */ + protected $type = 'Contract'; + /** * The console command description. * @@ -19,32 +29,31 @@ class ModelContractMakeCommand extends MakeCommand protected $description = 'Create a new model contract.'; /** - * @return mixed + * Get the stub file for the generator. */ - protected function getStubContents() + protected function getStubContents(): string { return $this->packageGenerator->getStubContents('model-contract', $this->getStubVariables()); } /** - * @return array + * Get the stub variables. */ - protected function getStubVariables() + protected function getStubVariables(): array { return [ - 'NAMESPACE' => $this->getClassNamespace($this->argument('package') . '/Contracts'), + 'NAMESPACE' => $this->getClassNamespace($this->argument('package').'/Contracts'), 'CLASS' => $this->getClassName(), ]; } /** - * @return string + * Get the source file path. */ - protected function getSourceFilePath() + protected function getSourceFilePath(): string { - $path = base_path('packages/' . $this->argument('package')) . '/src/Contracts'; + $path = base_path('packages/'.$this->argument('package')).'/src/Contracts'; - return $path . '/' . $this->getClassName() . '.php'; + return "$path/{$this->getClassName()}.php"; } - -} \ No newline at end of file +} diff --git a/src/Console/Command/ModelMakeCommand.php b/src/Console/Command/ModelMakeCommand.php index 1acea7f..561ea2a 100644 --- a/src/Console/Command/ModelMakeCommand.php +++ b/src/Console/Command/ModelMakeCommand.php @@ -2,6 +2,9 @@ namespace Webkul\PackageGenerator\Console\Command; +use Symfony\Component\Console\Attribute\AsCommand; + +#[AsCommand(name: 'package:make-model')] class ModelMakeCommand extends MakeCommand { /** @@ -11,6 +14,13 @@ class ModelMakeCommand extends MakeCommand */ protected $signature = 'package:make-model {name} {package} {--force}'; + /** + * The type of class being generated. + * + * @var string + */ + protected $type = 'Model'; + /** * The console command description. * @@ -26,7 +36,7 @@ public function handle() parent::handle(); $this->call('package:make-model-proxy', [ - 'name' => $this->argument('name') . 'Proxy', + 'name' => $this->argument('name').'Proxy', 'package' => $this->argument('package'), '--force' => $this->option('force'), ]); @@ -39,32 +49,32 @@ public function handle() } /** - * @return mixed + * Get the stub file for the generator. */ - protected function getStubContents() + protected function getStubContents(): string { return $this->packageGenerator->getStubContents('model', $this->getStubVariables()); } /** - * @return array + * Get the stub variables. */ - protected function getStubVariables() + protected function getStubVariables(): array { return [ 'PACKAGE' => $this->getClassNamespace($this->argument('package')), - 'NAMESPACE' => $this->getClassNamespace($this->argument('package') . '/Models'), + 'NAMESPACE' => $this->getClassNamespace($this->argument('package').'/Models'), 'CLASS' => $this->getClassName(), ]; } /** - * @return string + * Get the source file path. */ - protected function getSourceFilePath() + protected function getSourceFilePath(): string { - $path = base_path('packages/' . $this->argument('package')) . '/src/Models'; + $path = base_path('packages/'.$this->argument('package')).'/src/Models'; - return $path . '/' . $this->getClassName() . '.php'; + return "$path/{$this->getClassName()}.php"; } -} \ No newline at end of file +} diff --git a/src/Console/Command/ModelProxyMakeCommand.php b/src/Console/Command/ModelProxyMakeCommand.php index 028c13b..781e722 100644 --- a/src/Console/Command/ModelProxyMakeCommand.php +++ b/src/Console/Command/ModelProxyMakeCommand.php @@ -2,6 +2,9 @@ namespace Webkul\PackageGenerator\Console\Command; +use Symfony\Component\Console\Attribute\AsCommand; + +#[AsCommand(name: 'package:make-model-proxy')] class ModelProxyMakeCommand extends MakeCommand { /** @@ -11,6 +14,13 @@ class ModelProxyMakeCommand extends MakeCommand */ protected $signature = 'package:make-model-proxy {name} {package} {--force}'; + /** + * The type of class being generated. + * + * @var string + */ + protected $type = 'Model Proxy'; + /** * The console command description. * @@ -19,32 +29,31 @@ class ModelProxyMakeCommand extends MakeCommand protected $description = 'Create a new model proxy.'; /** - * @return mixed + * Get the stub file for the generator. */ - protected function getStubContents() + protected function getStubContents(): string { return $this->packageGenerator->getStubContents('model-proxy', $this->getStubVariables()); } /** - * @return array + * Get the stub variables. */ - protected function getStubVariables() + protected function getStubVariables(): array { return [ - 'NAMESPACE' => $this->getClassNamespace($this->argument('package') . '/Models'), + 'NAMESPACE' => $this->getClassNamespace($this->argument('package').'/Models'), 'CLASS' => $this->getClassName(), ]; } /** - * @return string + * Get the source file path. */ - protected function getSourceFilePath() + protected function getSourceFilePath(): string { - $path = base_path('packages/' . $this->argument('package')) . '/src/Models'; + $path = base_path('packages/'.$this->argument('package')).'/src/Models'; - return $path . '/' . $this->getClassName() . '.php'; + return "$path/{$this->getClassName()}.php"; } - -} \ No newline at end of file +} diff --git a/src/Console/Command/ModuleProviderMakeCommand.php b/src/Console/Command/ModuleProviderMakeCommand.php index 4dfde20..b35dc30 100644 --- a/src/Console/Command/ModuleProviderMakeCommand.php +++ b/src/Console/Command/ModuleProviderMakeCommand.php @@ -2,8 +2,9 @@ namespace Webkul\PackageGenerator\Console\Command; -use Webkul\PackageGenerator\Generators\PackageGenerator; +use Symfony\Component\Console\Attribute\AsCommand; +#[AsCommand(name: 'package:make-module-provider')] class ModuleProviderMakeCommand extends MakeCommand { /** @@ -13,6 +14,13 @@ class ModuleProviderMakeCommand extends MakeCommand */ protected $signature = 'package:make-module-provider {name} {package} {--force}'; + /** + * The type of class being generated. + * + * @var string + */ + protected $type = 'Module Provider'; + /** * The console command description. * @@ -21,31 +29,31 @@ class ModuleProviderMakeCommand extends MakeCommand protected $description = 'Create a new module service provider.'; /** - * @return mixed + * Get the stub file for the generator. */ - protected function getStubContents() + protected function getStubContents(): string { return $this->packageGenerator->getStubContents('scaffold/module-provider', $this->getStubVariables()); } /** - * @return array + * Get the stub variables. */ - protected function getStubVariables() + protected function getStubVariables(): array { return [ - 'NAMESPACE' => $this->getClassNamespace($this->argument('package') . '/Providers'), + 'NAMESPACE' => $this->getClassNamespace($this->argument('package').'/Providers'), 'CLASS' => $this->getClassName(), ]; } /** - * @return string + * Get the source file path. */ - protected function getSourceFilePath() + protected function getSourceFilePath(): string { - $path = base_path('packages/' . $this->argument('package')) . '/src/Providers'; + $path = base_path('packages/'.$this->argument('package')).'/src/Providers'; - return $path . '/' . $this->getClassName() . '.php'; + return "$path/{$this->getClassName()}.php"; } -} \ No newline at end of file +} diff --git a/src/Console/Command/NotificationMakeCommand.php b/src/Console/Command/NotificationMakeCommand.php index 0e59feb..cb4cee9 100644 --- a/src/Console/Command/NotificationMakeCommand.php +++ b/src/Console/Command/NotificationMakeCommand.php @@ -2,6 +2,9 @@ namespace Webkul\PackageGenerator\Console\Command; +use Symfony\Component\Console\Attribute\AsCommand; + +#[AsCommand(name: 'package:make-notification')] class NotificationMakeCommand extends MakeCommand { /** @@ -11,6 +14,13 @@ class NotificationMakeCommand extends MakeCommand */ protected $signature = 'package:make-notification {name} {package} {--force}'; + /** + * The type of class being generated. + * + * @var string + */ + protected $type = 'Notification'; + /** * The console command description. * @@ -19,31 +29,31 @@ class NotificationMakeCommand extends MakeCommand protected $description = 'Create a new notification.'; /** - * @return mixed + * Get the stub file for the generator. */ - protected function getStubContents() + protected function getStubContents(): string { return $this->packageGenerator->getStubContents('notification', $this->getStubVariables()); } /** - * @return array + * Get the stub variables. */ - protected function getStubVariables() + protected function getStubVariables(): array { return [ - 'NAMESPACE' => $this->getClassNamespace($this->argument('package') . '/Notifications'), + 'NAMESPACE' => $this->getClassNamespace($this->argument('package').'/Notifications'), 'CLASS' => $this->getClassName(), ]; } /** - * @return string + * Get the source file path. */ - protected function getSourceFilePath() + protected function getSourceFilePath(): string { - $path = base_path('packages/' . $this->argument('package')) . '/src/Notifications'; + $path = base_path('packages/'.$this->argument('package')).'/src/Notifications'; - return $path . '/' . $this->getClassName() . '.php'; + return "$path/{$this->getClassName()}.php"; } -} \ No newline at end of file +} diff --git a/src/Console/Command/PackageMakeCommand.php b/src/Console/Command/PackageMakeCommand.php index 2c7c8c4..0b0b151 100644 --- a/src/Console/Command/PackageMakeCommand.php +++ b/src/Console/Command/PackageMakeCommand.php @@ -2,8 +2,9 @@ namespace Webkul\PackageGenerator\Console\Command; -use Webkul\PackageGenerator\Generators\PackageGenerator; +use Symfony\Component\Console\Attribute\AsCommand; +#[AsCommand(name: 'package:make')] class PackageMakeCommand extends MakeCommand { /** @@ -13,6 +14,13 @@ class PackageMakeCommand extends MakeCommand */ protected $signature = 'package:make {package} {--plain} {--force}'; + /** + * The type of class being generated. + * + * @var string + */ + protected $type = 'Package'; + /** * The console command description. * @@ -25,10 +33,12 @@ class PackageMakeCommand extends MakeCommand */ public function handle() { - $this->packageGenerator->setConsole($this) + $this->packageGenerator + ->setPackageGenerator($this) + ->setConsole($this->components) ->setPackage($this->argument('package')) ->setPlain($this->option('plain')) ->setForce($this->option('force')) ->generate(); } -} \ No newline at end of file +} diff --git a/src/Console/Command/ProviderMakeCommand.php b/src/Console/Command/ProviderMakeCommand.php index 6c99285..92cc4c2 100644 --- a/src/Console/Command/ProviderMakeCommand.php +++ b/src/Console/Command/ProviderMakeCommand.php @@ -2,9 +2,9 @@ namespace Webkul\PackageGenerator\Console\Command; -use Illuminate\Support\Str; -use Webkul\PackageGenerator\Generators\PackageGenerator; +use Symfony\Component\Console\Attribute\AsCommand; +#[AsCommand(name: 'package:make-provider')] class ProviderMakeCommand extends MakeCommand { /** @@ -14,6 +14,13 @@ class ProviderMakeCommand extends MakeCommand */ protected $signature = 'package:make-provider {name} {package} {--force}'; + /** + * The type of class being generated. + * + * @var string + */ + protected $type = 'Provider'; + /** * The console command description. * @@ -22,9 +29,9 @@ class ProviderMakeCommand extends MakeCommand protected $description = 'Create a new service provider.'; /** - * @return mixed + * Get the stub file for the generator. */ - protected function getStubContents() + protected function getStubContents(): string { $stub = $this->hasOption('plain') ? 'provider' : 'scaffold/package-provider'; @@ -32,24 +39,24 @@ protected function getStubContents() } /** - * @return array + * Get the stub variables. */ - protected function getStubVariables() + protected function getStubVariables(): array { return [ - 'NAMESPACE' => $this->getClassNamespace($this->argument('package') . '/Providers'), + 'NAMESPACE' => $this->getClassNamespace($this->argument('package').'/Providers'), 'CLASS' => $this->getClassName(), 'LOWER_NAME' => $this->getLowerName(), ]; } /** - * @return string + * Get the source file path. */ - protected function getSourceFilePath() + protected function getSourceFilePath(): string { - $path = base_path('packages/' . $this->argument('package')) . '/src/Providers'; + $path = base_path('packages/'.$this->argument('package')).'/src/Providers'; - return $path . '/' . $this->getClassName() . '.php'; + return "$path/{$this->getClassName()}.php"; } -} \ No newline at end of file +} diff --git a/src/Console/Command/RepositoryMakeCommand.php b/src/Console/Command/RepositoryMakeCommand.php index 17140b2..9994710 100644 --- a/src/Console/Command/RepositoryMakeCommand.php +++ b/src/Console/Command/RepositoryMakeCommand.php @@ -2,6 +2,9 @@ namespace Webkul\PackageGenerator\Console\Command; +use Symfony\Component\Console\Attribute\AsCommand; + +#[AsCommand(name: 'package:make-repository')] class RepositoryMakeCommand extends MakeCommand { /** @@ -11,6 +14,11 @@ class RepositoryMakeCommand extends MakeCommand */ protected $signature = 'package:make-repository {name} {package} {--force}'; + /** + * The type of class being generated. + */ + protected $type = 'Repository'; + /** * The console command description. * @@ -19,40 +27,40 @@ class RepositoryMakeCommand extends MakeCommand protected $description = 'Create a new repository.'; /** - * @return mixed + * Get the stub file for the generator. */ - protected function getStubContents() + protected function getStubContents(): string { return $this->packageGenerator->getStubContents('repository', $this->getStubVariables()); } /** - * @return array + * Get the stub variables. */ - protected function getStubVariables() + protected function getStubVariables(): array { return [ - 'NAMESPACE' => $this->getClassNamespace($this->argument('package') . '/Repositories'), + 'NAMESPACE' => $this->getClassNamespace($this->argument('package').'/Repositories'), 'CLASS' => $this->getClassName(), - 'CONTRACT_CLASS' => $this->getClassNamespace($this->argument('package') . '/Contracts/' . $this->getContractName()), + 'CONTRACT_CLASS' => $this->getClassNamespace($this->argument('package').'/Contracts/'.$this->getContractName()), ]; } /** - * @return string + * Get the source file path. */ - protected function getSourceFilePath() + protected function getSourceFilePath(): string { - $path = base_path('packages/' . $this->argument('package')) . '/src/Repositories'; + $path = base_path('packages/'.$this->argument('package')).'/src/Repositories'; - return $path . '/' . $this->getClassName() . '.php'; + return "$path/{$this->getClassName()}.php"; } /** - * @return string + * Get the contract name. */ - protected function getContractName() + protected function getContractName(): string { return str_replace('Repository', '', $this->argument('name')); } -} \ No newline at end of file +} diff --git a/src/Console/Command/RequestMakeCommand.php b/src/Console/Command/RequestMakeCommand.php index 7551d5a..9baa3cb 100644 --- a/src/Console/Command/RequestMakeCommand.php +++ b/src/Console/Command/RequestMakeCommand.php @@ -2,6 +2,9 @@ namespace Webkul\PackageGenerator\Console\Command; +use Symfony\Component\Console\Attribute\AsCommand; + +#[AsCommand(name: 'package:make-request')] class RequestMakeCommand extends MakeCommand { /** @@ -11,6 +14,13 @@ class RequestMakeCommand extends MakeCommand */ protected $signature = 'package:make-request {name} {package} {--force}'; + /** + * The type of class being generated. + * + * @var string + */ + protected $type = 'Request'; + /** * The console command description. * @@ -19,31 +29,31 @@ class RequestMakeCommand extends MakeCommand protected $description = 'Create a new request.'; /** - * @return mixed + * Get the stub file for the generator. */ - protected function getStubContents() + protected function getStubContents(): string { return $this->packageGenerator->getStubContents('request', $this->getStubVariables()); } /** - * @return array + * Get the stub variables. */ - protected function getStubVariables() + protected function getStubVariables(): array { return [ - 'NAMESPACE' => $this->getClassNamespace($this->argument('package') . '/Http/Requests'), + 'NAMESPACE' => $this->getClassNamespace($this->argument('package').'/Http/Requests'), 'CLASS' => $this->getClassName(), ]; } /** - * @return string + * Get the source file path. */ - protected function getSourceFilePath() + protected function getSourceFilePath(): string { - $path = base_path('packages/' . $this->argument('package')) . '/src/Http/Requests'; + $path = base_path('packages/'.$this->argument('package')).'/src/Http/Requests'; - return $path . '/' . $this->getClassName() . '.php'; + return "$path/{$this->getClassName()}.php"; } -} \ No newline at end of file +} diff --git a/src/Console/Command/RouteMakeCommand.php b/src/Console/Command/RouteMakeCommand.php index 1c4339d..67cec4c 100644 --- a/src/Console/Command/RouteMakeCommand.php +++ b/src/Console/Command/RouteMakeCommand.php @@ -2,9 +2,9 @@ namespace Webkul\PackageGenerator\Console\Command; -use Illuminate\Support\Str; -use Webkul\PackageGenerator\Generators\PackageGenerator; +use Symfony\Component\Console\Attribute\AsCommand; +#[AsCommand(name: 'package:make-route')] class RouteMakeCommand extends MakeCommand { /** @@ -14,6 +14,13 @@ class RouteMakeCommand extends MakeCommand */ protected $signature = 'package:make-route {package} {--force}'; + /** + * The type of class being generated. + * + * @var string + */ + protected $type = 'Route'; + /** * The console command description. * @@ -22,31 +29,32 @@ class RouteMakeCommand extends MakeCommand protected $description = 'Create a new route file.'; /** - * @return mixed + * Get the stub file for the generator. */ - protected function getStubContents() + protected function getStubContents(): string { return $this->packageGenerator->getStubContents('routes', $this->getStubVariables()); } /** - * @return array + * Get the stub variables. */ - protected function getStubVariables() + protected function getStubVariables(): array { return [ - 'CONTROLLER_CLASS_NAME' => $this->getClassNamespace($this->argument('package') . '/Http/Controllers/' . $this->getStudlyName() . 'Controller'), + 'CONTROLLER_CLASS_NAME' => $this->getClassNamespace($this->argument('package').'/Http/Controllers/'.$this->getStudlyName().'Controller'), 'LOWER_NAME' => $this->getLowerName(), + 'CLASS_NAME' => "{$this->getStudlyName()}Controller", ]; } /** - * @return string + * Get the source file path. */ - protected function getSourceFilePath() + protected function getSourceFilePath(): string { - $path = base_path('packages/' . $this->argument('package')) . '/src/Http'; + $path = base_path('packages/'.$this->argument('package')).'/src/Routes'; - return $path . '/routes.php'; + return "$path/web.php"; } -} \ No newline at end of file +} diff --git a/src/Console/Command/SeederMakeCommand.php b/src/Console/Command/SeederMakeCommand.php index 9858b98..f63aadb 100644 --- a/src/Console/Command/SeederMakeCommand.php +++ b/src/Console/Command/SeederMakeCommand.php @@ -2,6 +2,9 @@ namespace Webkul\PackageGenerator\Console\Command; +use Symfony\Component\Console\Attribute\AsCommand; + +#[AsCommand(name: 'package:make-seeder')] class SeederMakeCommand extends MakeCommand { /** @@ -11,6 +14,13 @@ class SeederMakeCommand extends MakeCommand */ protected $signature = 'package:make-seeder {name} {package} {--force}'; + /** + * The type of class being generated. + * + * @var string + */ + protected $type = 'Seeder'; + /** * The console command description. * @@ -19,32 +29,31 @@ class SeederMakeCommand extends MakeCommand protected $description = 'Create a new seeder.'; /** - * @return mixed + * Get the stub file for the generator. */ - protected function getStubContents() + protected function getStubContents(): string { return $this->packageGenerator->getStubContents('seeder', $this->getStubVariables()); } /** - * @return array + * Get the stub variables. */ - protected function getStubVariables() + protected function getStubVariables(): array { return [ - 'NAMESPACE' => $this->getClassNamespace($this->argument('package') . '/Database/Seeders'), + 'NAMESPACE' => $this->getClassNamespace($this->argument('package').'/Database/Seeders'), 'CLASS' => $this->getClassName(), ]; } /** - * @return string + * Get the source file path. */ - protected function getSourceFilePath() + protected function getSourceFilePath(): string { - $path = base_path('packages/' . $this->argument('package')) . '/src/Database/Seeders'; + $path = base_path('packages/'.$this->argument('package')).'/src/Database/Seeders'; - return $path . '/' . $this->getClassName() . '.php'; + return "$path/{$this->getClassName()}.php"; } - -} \ No newline at end of file +} diff --git a/src/Generators/PackageGenerator.php b/src/Generators/PackageGenerator.php index b23604a..e4448f9 100644 --- a/src/Generators/PackageGenerator.php +++ b/src/Generators/PackageGenerator.php @@ -4,82 +4,80 @@ use Illuminate\Config\Repository as Config; use Illuminate\Filesystem\Filesystem; -use Illuminate\Support\Str; use Webkul\PackageGenerator\Package; class PackageGenerator { /** - * The package vendor namespace + * The package vendor namespace. * * @var string */ protected $vendorNamespace; /** - * The package name + * The package name. * * @var string */ protected $packageName; /** - * Repository object + * The plain agument. * - * @var \Illuminate\Config\Repository + * @var bool */ - protected $config; + protected $plain; /** - * Filesystem object + * The argument that make force the overrides. * - * @var \Illuminate\Filesystem\Filesystem + * @var bool */ - protected $filesystem; + protected $force; /** - * Package object + * Define the type of package. * * @var string */ - protected $package; - - /** - * @var boolean - */ - protected $plain; + protected $type = 'package'; /** - * @var boolean + * Contains console instance + * + * @var \Illuminate\Console\Command */ - protected $force; + protected $console; /** - * @var boolean + * Contains generator instance + * + * @var \Webkul\PackageGenerator\Console\Command */ - protected $type = 'package'; + protected $generator; /** * Contains subs files information * - * @var string + * @var array */ protected $stubFiles = [ 'package' => [ - 'views/layouts/style' => 'Resources/views/layouts/style.blade.php', + 'views/components/layouts/style' => 'Resources/views/components/layouts/style.blade.php', 'views/index' => 'Resources/views/index.blade.php', 'scaffold/menu' => 'Config/menu.php', 'scaffold/acl' => 'Config/acl.php', 'assets/js/app' => 'Resources/assets/js/app.js', - 'assets/sass/admin' => 'Resources/assets/sass/admin.scss', + 'assets/css/app' => 'Resources/assets/css/app.css', 'assets/images/Icon-Temp' => 'Resources/assets/images/Icon-Temp.svg', 'assets/images/Icon-Temp-Active' => 'Resources/assets/images/Icon-Temp-Active.svg', - 'assets/publishable/css/admin' => '../publishable/assets/css/admin.css', - 'assets/publishable/js/app' => '../publishable/assets/js/app.js', - 'assets/publishable/images/Icon-Temp' => '../publishable/assets/images/Icon-Temp.svg', - 'assets/publishable/images/Icon-Temp-Active' => '../publishable/assets/images/Icon-Temp-Active.svg', - 'webpack' => '../webpack.mix.js', 'package' => '../package.json', + 'vite' => '../vite.config.js', + 'tailwind' => '../tailwind.config.js', + 'postcss' => '../postcss.config.js', + '.gitignore' => '../.gitignore', + 'composer' => '../composer.json', ], ]; @@ -112,32 +110,30 @@ class PackageGenerator ]; /** - * The constructor. - * - * @param \Illuminate\Config\Repository $config - * @param \Illuminate\Filesystem\Filesystem $filesystem - * @param \Webkul\PackageGenerator\Package $package + * Create a new generator instance. + * + * @return void */ public function __construct( - Config $config, - Filesystem $filesystem, - Package $package - ) - { - $this->config = $config; + protected Config $config, + protected Filesystem $filesystem, + protected Package $package + ) {} - $this->filesystem = $filesystem; + /** + * Set generator + */ + public function setPackageGenerator(mixed $generator): self + { + $this->generator = $generator; - $this->package = $package; + return $this; } /** - * Set console - * - * @param \Illuminate\Console\Command $console - * @return Webkul\PackageGenerator\Generators\PackageGenerator + * Set console */ - public function setConsole($console) + public function setConsole(mixed $console): self { $this->console = $console; @@ -146,11 +142,8 @@ public function setConsole($console) /** * Set package. - * - * @param string $packageName - * @return Webkul\PackageGenerator\Generators\PackageGenerator */ - public function setPackage($packageName) + public function setPackage(mixed $packageName): self { $this->packageName = $packageName; @@ -159,11 +152,8 @@ public function setPackage($packageName) /** * Set package plain. - * - * @param string $plain - * @return Webkul\PackageGenerator\Generators\PackageGenerator */ - public function setPlain($plain) + public function setPlain(mixed $plain): self { $this->plain = $plain; @@ -172,11 +162,8 @@ public function setPlain($plain) /** * Set force status. - * - * @param boolean $force - * @return \Webkul\PackageGenerator\Generators\PackageGenerator */ - public function setForce($force) + public function setForce(mixed $force): self { $this->force = $force; @@ -185,11 +172,8 @@ public function setForce($force) /** * Set type status. - * - * @param boolean $isPaymentPackage - * @return \Webkul\PackageGenerator\Generators\PackageGenerator */ - public function setType($type) + public function setType(string $type): self { $this->type = $type; @@ -198,16 +182,14 @@ public function setType($type) /** * Generate package - * - * @return void */ - public function generate() + public function generate(): void { if ($this->package->has($this->packageName)) { if ($this->force) { $this->package->delete($this->packageName); } else { - $this->console->error("Package '{$this->packageName}' already exist !"); + $this->console->error(sprintf('Package %s already exist !', $this->packageName)); return; } @@ -221,18 +203,16 @@ public function generate() $this->createClasses(); } - $this->console->info("Package '{$this->packageName}' created successfully."); + $this->console->info(sprintf('Package %s created successfully.', $this->packageName)); } /** * Generate package folders - * - * @return void */ - public function createFolders() + public function createFolders(): void { foreach ($this->paths[$this->type] as $key => $folder) { - $path = base_path('packages/' . $this->packageName . '/src') . '/' . $folder; + $path = base_path('packages/'.$this->packageName.'/src').'/'.$folder; $this->filesystem->makeDirectory($path, 0755, true); } @@ -240,15 +220,13 @@ public function createFolders() /** * Generate package files - * - * @return void */ - public function createFiles() + public function createFiles(): void { $variables = $this->getStubVariables(); foreach ($this->stubFiles[$this->type] as $stub => $file) { - $path = base_path('packages/' . $this->packageName . '/src') . '/' . $file; + $path = base_path('packages/'.$this->packageName.'/src').'/'.$file; if (! $this->filesystem->isDirectory($dir = dirname($path))) { $this->filesystem->makeDirectory($dir, 0775, true); @@ -262,37 +240,35 @@ public function createFiles() /** * Generate package classes - * - * @return void */ - public function createClasses() + public function createClasses(): void { if ($this->type == 'package') { - $this->console->call('package:make-provider', [ - 'name' => $this->packageName . 'ServiceProvider', + $this->generator->call('package:make-provider', [ + 'name' => $this->packageName.'ServiceProvider', 'package' => $this->packageName, ]); - $this->console->call('package:make-module-provider', [ + $this->generator->call('package:make-module-provider', [ 'name' => 'ModuleServiceProvider', 'package' => $this->packageName, ]); - $this->console->call('package:make-controller', [ - 'name' => $this->packageName . 'Controller', - 'package' => $this->packageName + $this->generator->call('package:make-controller', [ + 'name' => $this->packageName.'Controller', + 'package' => $this->packageName, ]); - $this->console->call('package:make-route', [ - 'package' => $this->packageName + $this->generator->call('package:make-route', [ + 'package' => $this->packageName, ]); } } /** - * @return array + * Get the variables for the stub file. */ - protected function getStubVariables() + protected function getStubVariables(): array { return [ 'LOWER_NAME' => $this->getLowerName(), @@ -303,55 +279,50 @@ protected function getStubVariables() } /** - * @return string + * Get the class name of the package. */ - protected function getClassName() + protected function getClassName(): string { return class_basename($this->packageName); } /** - * @param string $name - * @return string + * Get the class namespace of the package. */ - protected function getClassNamespace($name) + protected function getClassNamespace($name): array|string { return str_replace('/', '\\', $name); } /** * Returns content of stub file - * - * @param string $stub - * @param array $variables - * @return string */ - public function getStubContents($stub, $variables = []) + public function getStubContents(string $stub, array $variables = []): mixed { - $path = __DIR__ . '/../stubs/' . $stub . '.stub'; + $path = __DIR__.'/../stubs/'.$stub.'.stub'; $contents = file_get_contents($path); foreach ($variables as $search => $replace) { - $contents = str_replace('$' . strtoupper($search) . '$', $replace, $contents); + $contents = str_replace('$'.strtoupper($search).'$', $replace, $contents); } return $contents; } /** - * @return string + * Get the capitalize name of the package. */ - protected function getCapitalizeName() + protected function getCapitalizeName(): string { return ucwords(class_basename($this->packageName)); } /** - * @return string + * Get the lower name of the package. */ - protected function getLowerName() + protected function getLowerName(): string { return strtolower(class_basename($this->packageName)); } -} \ No newline at end of file +} diff --git a/src/Package.php b/src/Package.php index 1689092..2628769 100644 --- a/src/Package.php +++ b/src/Package.php @@ -8,8 +8,6 @@ class Package { /** * The constructor. - * - * @param \Illuminate\Filesystem\Filesystem $filesystem */ public function __construct(Filesystem $filesystem) { @@ -20,11 +18,11 @@ public function __construct(Filesystem $filesystem) * Checks if package exist or not * * @param strign $package - * @return boolean + * @return bool */ public function has($package) { - return $this->filesystem->isDirectory(base_path('packages/' . $package)); + return $this->filesystem->isDirectory(base_path('packages/'.$package)); } /** @@ -35,6 +33,6 @@ public function has($package) */ public function delete($package) { - $this->filesystem->deleteDirectory(base_path('packages/' . $package)); + $this->filesystem->deleteDirectory(base_path('packages/'.$package)); } -} \ No newline at end of file +} diff --git a/src/Providers/PackageGeneratorServiceProvider.php b/src/Providers/PackageGeneratorServiceProvider.php index 916583e..59f69a6 100644 --- a/src/Providers/PackageGeneratorServiceProvider.php +++ b/src/Providers/PackageGeneratorServiceProvider.php @@ -3,41 +3,35 @@ namespace Webkul\PackageGenerator\Providers; use Illuminate\Support\ServiceProvider; -use Webkul\PackageGenerator\Console\Command\PackageMakeCommand; -use Webkul\PackageGenerator\Console\Command\ProviderMakeCommand; -use Webkul\PackageGenerator\Console\Command\ModuleProviderMakeCommand; +use Webkul\PackageGenerator\Console\Command\CommandMakeCommand; use Webkul\PackageGenerator\Console\Command\ControllerMakeCommand; -use Webkul\PackageGenerator\Console\Command\RouteMakeCommand; +use Webkul\PackageGenerator\Console\Command\DatagridMakeCommand; +use Webkul\PackageGenerator\Console\Command\EventMakeCommand; +use Webkul\PackageGenerator\Console\Command\ListenerMakeCommand; +use Webkul\PackageGenerator\Console\Command\MailMakeCommand; +use Webkul\PackageGenerator\Console\Command\MiddlewareMakeCommand; use Webkul\PackageGenerator\Console\Command\MigrationMakeCommand; +use Webkul\PackageGenerator\Console\Command\ModelContractMakeCommand; use Webkul\PackageGenerator\Console\Command\ModelMakeCommand; use Webkul\PackageGenerator\Console\Command\ModelProxyMakeCommand; -use Webkul\PackageGenerator\Console\Command\ModelContractMakeCommand; +use Webkul\PackageGenerator\Console\Command\ModuleProviderMakeCommand; +use Webkul\PackageGenerator\Console\Command\NotificationMakeCommand; +use Webkul\PackageGenerator\Console\Command\PackageMakeCommand; +use Webkul\PackageGenerator\Console\Command\ProviderMakeCommand; use Webkul\PackageGenerator\Console\Command\RepositoryMakeCommand; -use Webkul\PackageGenerator\Console\Command\SeederMakeCommand; -use Webkul\PackageGenerator\Console\Command\MailMakeCommand; -use Webkul\PackageGenerator\Console\Command\CommandMakeCommand; -use Webkul\PackageGenerator\Console\Command\EventMakeCommand; -use Webkul\PackageGenerator\Console\Command\ListenerMakeCommand; -use Webkul\PackageGenerator\Console\Command\MiddlewareMakeCommand; use Webkul\PackageGenerator\Console\Command\RequestMakeCommand; -use Webkul\PackageGenerator\Console\Command\NotificationMakeCommand; -use Webkul\PackageGenerator\Console\Command\DatagridMakeCommand; +use Webkul\PackageGenerator\Console\Command\RouteMakeCommand; +use Webkul\PackageGenerator\Console\Command\SeederMakeCommand; class PackageGeneratorServiceProvider extends ServiceProvider { /** * Bootstrap services. - * - * @return void */ - public function boot(): void - { - } + public function boot(): void {} /** * Register services. - * - * @return void */ public function register(): void { @@ -46,8 +40,6 @@ public function register(): void /** * Register the console commands of this package - * - * @return void */ protected function registerCommands(): void { @@ -75,4 +67,4 @@ protected function registerCommands(): void ]); } } -} \ No newline at end of file +} diff --git a/src/stubs/.gitignore.stub b/src/stubs/.gitignore.stub new file mode 100644 index 0000000..b1cb477 --- /dev/null +++ b/src/stubs/.gitignore.stub @@ -0,0 +1,3 @@ +/node_modules +/npm-debug.log +/package-lock.json diff --git a/src/stubs/assets/css/app.stub b/src/stubs/assets/css/app.stub new file mode 100644 index 0000000..e69de29 diff --git a/src/stubs/assets/js/app.stub b/src/stubs/assets/js/app.stub index e69de29..a60dced 100644 --- a/src/stubs/assets/js/app.stub +++ b/src/stubs/assets/js/app.stub @@ -0,0 +1,4 @@ +/** + * This will track all the images and fonts for publishing. + */ +import.meta.glob(["../images/**", "../fonts/**"]); diff --git a/src/stubs/assets/publishable/css/admin.stub b/src/stubs/assets/publishable/css/admin.stub deleted file mode 100644 index 1a17a04..0000000 --- a/src/stubs/assets/publishable/css/admin.stub +++ /dev/null @@ -1 +0,0 @@ -.temp-icon{width:48px;height:48px;display:inline-block;background-size:cover;background-image:url(../images/Icon-Temp.svg)}.active.temp-icon,.active .temp-icon{background-image:url(../images/Icon-Temp-Active.svg)} \ No newline at end of file diff --git a/src/stubs/assets/publishable/images/Icon-Temp-Active.stub b/src/stubs/assets/publishable/images/Icon-Temp-Active.stub deleted file mode 100755 index d4c6168..0000000 --- a/src/stubs/assets/publishable/images/Icon-Temp-Active.stub +++ /dev/null @@ -1,12 +0,0 @@ - - - - Icon-Catalog-Active - Created with Sketch. - - - - - - - \ No newline at end of file diff --git a/src/stubs/assets/publishable/images/Icon-Temp.stub b/src/stubs/assets/publishable/images/Icon-Temp.stub deleted file mode 100755 index 7dba04b..0000000 --- a/src/stubs/assets/publishable/images/Icon-Temp.stub +++ /dev/null @@ -1,12 +0,0 @@ - - - - Icon-Catalog - Created with Sketch. - - - - - - - \ No newline at end of file diff --git a/src/stubs/assets/publishable/js/app.stub b/src/stubs/assets/publishable/js/app.stub deleted file mode 100644 index 9fa3a91..0000000 --- a/src/stubs/assets/publishable/js/app.stub +++ /dev/null @@ -1 +0,0 @@ -!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/",n(n.s=0)}({0:function(e,t,n){n("uPOf"),n("y62a"),n("jTz4"),e.exports=n("WyvX")},WyvX:function(e,t){},jTz4:function(e,t){},uPOf:function(e,t){},y62a:function(e,t){}}); \ No newline at end of file diff --git a/src/stubs/assets/sass/admin.stub b/src/stubs/assets/sass/admin.stub deleted file mode 100644 index f9cde7e..0000000 --- a/src/stubs/assets/sass/admin.stub +++ /dev/null @@ -1,17 +0,0 @@ -.temp-icon { - width: 48px; - height: 48px; - display: inline-block; - background-size: cover; - background-image: url("../images/Icon-Temp.svg"); -} - -.active { - .temp-icon { - background-image: url("../images/Icon-Temp-Active.svg"); - } - - &.temp-icon { - background-image: url("../images/Icon-Temp-Active.svg"); - } -} diff --git a/src/stubs/command.stub b/src/stubs/command.stub index 4ca48b0..02197ac 100644 --- a/src/stubs/command.stub +++ b/src/stubs/command.stub @@ -20,16 +20,6 @@ class $CLASS$ extends Command */ protected $description = 'Command description'; - /** - * Create a new command instance. - * - * @return void - */ - public function __construct() - { - parent::__construct(); - } - /** * Execute the console command. * diff --git a/src/stubs/composer.stub b/src/stubs/composer.stub new file mode 100644 index 0000000..9adb1eb --- /dev/null +++ b/src/stubs/composer.stub @@ -0,0 +1,27 @@ +{ + "name": "$LOWER_NAME$/$LOWER_NAME$", + "description": "$LOWER_NAME$", + "license": "MIT", + "authors": [ + { + "name": "Webkul", + "email": "example@webkul.com" + } + ], + "require": { + }, + "autoload": { + "psr-4": { + "$PACKAGE$\\$PACKAGE$\\": "src/" + } + }, + "extra": { + "laravel": { + "providers": [ + "Webkul\\$PACKAGE$\\Providers\\$PACKAGE$ServiceProvider" + ], + "aliases": {} + } + }, + "minimum-stability": "dev" +} \ No newline at end of file diff --git a/src/stubs/datagrid.stub b/src/stubs/datagrid.stub index 1063aaf..549c0e4 100644 --- a/src/stubs/datagrid.stub +++ b/src/stubs/datagrid.stub @@ -2,35 +2,50 @@ namespace $NAMESPACE$; +use Illuminate\Database\Query\Builder; use Illuminate\Support\Facades\DB; -use Webkul\UI\DataGrid\DataGrid; +use Webkul\DataGrid\DataGrid; class $CLASS$ extends DataGrid { - protected $index = 'id'; - - protected $sortOrder = 'desc'; - - public function prepareQueryBuilder() + /** + * Prepare query builder. + */ + public function prepareQueryBuilder(): Builder { - //queryBuilder = DB::table('table')->addSelect('id'); + $queryBuilder = DB::table('table_name')->addSelect('id'); - //$this->setQueryBuilder($queryBuilder); + return $queryBuilder; } - public function addColumns() + /** + * Prepare columns. + */ + public function prepareColumns(): void { $this->addColumn([ 'index' => 'id', - 'label' => 'Id', - 'type' => 'number', - 'searchable' => false, + 'label' => 'ID', + 'type' => 'string', 'sortable' => true, + 'searchable' => true, 'filterable' => true, ]); } - public function prepareActions() + /** + * Prepare actions. + */ + public function prepareActions(): void + { + // + } + + /** + * Prepare mass actions. + */ + public function prepareMassActions(): void { + // } -} \ No newline at end of file +} diff --git a/src/stubs/event.stub b/src/stubs/event.stub index 224700d..8574f3f 100644 --- a/src/stubs/event.stub +++ b/src/stubs/event.stub @@ -16,7 +16,7 @@ class $CLASS$ /** * Create a new event instance. - * + * * @return void */ public function __construct() @@ -27,10 +27,12 @@ class $CLASS$ /** * Get the channels the event should broadcast on. * - * @return \Illuminate\Broadcasting\Channel|array + * @return array */ - public function broadcastOn() + public function broadcastOn(): array { - return new PrivateChannel('channel-name'); + return [ + new PrivateChannel('channel-name'), + ]; } } diff --git a/src/stubs/listener.stub b/src/stubs/listener.stub index 455e119..d7655fa 100644 --- a/src/stubs/listener.stub +++ b/src/stubs/listener.stub @@ -19,11 +19,8 @@ class $CLASS$ /** * Handle the event. - * - * @param object $event - * @return void */ - public function handle($event) + public function handle(object $event): void { // } diff --git a/src/stubs/mail.stub b/src/stubs/mail.stub index 31b2093..447b73f 100644 --- a/src/stubs/mail.stub +++ b/src/stubs/mail.stub @@ -5,6 +5,8 @@ namespace $NAMESPACE$; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Mail\Mailable; +use Illuminate\Mail\Mailables\Content; +use Illuminate\Mail\Mailables\Envelope; use Illuminate\Queue\SerializesModels; class $CLASS$ extends Mailable @@ -22,12 +24,32 @@ class $CLASS$ extends Mailable } /** - * Build the message. + * Get the message envelope. + */ + public function envelope(): Envelope + { + return new Envelope( + subject: '$LOWER_NAME$', + ); + } + + /** + * Get the message content definition. + */ + public function content(): Content + { + return new Content( + view: 'view.name', + ); + } + + /** + * Get the attachments for the message. * - * @return $this + * @return array */ - public function build() + public function attachments(): array { - return $this->view('view.name'); + return []; } -} \ No newline at end of file +} diff --git a/src/stubs/middleware.stub b/src/stubs/middleware.stub index fa6d687..90fa287 100644 --- a/src/stubs/middleware.stub +++ b/src/stubs/middleware.stub @@ -3,18 +3,18 @@ namespace $NAMESPACE$; use Closure; +use Illuminate\Http\Request; +use Symfony\Component\HttpFoundation\Response; class $CLASS$ { /** * Handle an incoming request. * - * @param \Illuminate\Http\Request $request - * @param \Closure $next - * @return mixed + * @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next */ - public function handle($request, Closure $next) + public function handle(Request $request, Closure $next): Response { return $next($request); } -} \ No newline at end of file +} diff --git a/src/stubs/model-contract.stub b/src/stubs/model-contract.stub index 1902904..c8ea272 100644 --- a/src/stubs/model-contract.stub +++ b/src/stubs/model-contract.stub @@ -4,4 +4,4 @@ namespace $NAMESPACE$; interface $CLASS$ { -} \ No newline at end of file +} diff --git a/src/stubs/model-proxy.stub b/src/stubs/model-proxy.stub index 31a8cf9..77afb2b 100644 --- a/src/stubs/model-proxy.stub +++ b/src/stubs/model-proxy.stub @@ -4,7 +4,4 @@ namespace $NAMESPACE$; use Konekt\Concord\Proxies\ModelProxy; -class $CLASS$ extends ModelProxy -{ - -} \ No newline at end of file +class $CLASS$ extends ModelProxy {} diff --git a/src/stubs/notification.stub b/src/stubs/notification.stub index 7ab38dd..364abf9 100644 --- a/src/stubs/notification.stub +++ b/src/stubs/notification.stub @@ -13,8 +13,6 @@ class $CLASS$ extends Notification /** * Create a new notification instance. - * - * @return void */ public function __construct() { @@ -24,38 +22,33 @@ class $CLASS$ extends Notification /** * Get the notification's delivery channels. * - * @param mixed $notifiable - * @return array + * @return array */ - public function via($notifiable) + public function via(object $notifiable): array { return ['mail']; } /** * Get the mail representation of the notification. - * - * @param mixed $notifiable - * @return \Illuminate\Notifications\Messages\MailMessage */ - public function toMail($notifiable) + public function toMail(object $notifiable): MailMessage { return (new MailMessage) ->line('The introduction to the notification.') ->action('Notification Action', url('/')) ->line('Thank you for using our application!'); } - + /** * Get the array representation of the notification. * - * @param mixed $notifiable - * @return array + * @return array */ - public function toArray($notifiable) + public function toArray(object $notifiable): array { return [ // ]; } -} \ No newline at end of file +} diff --git a/src/stubs/package.stub b/src/stubs/package.stub index 5f0b6e2..50f8429 100644 --- a/src/stubs/package.stub +++ b/src/stubs/package.stub @@ -1,26 +1,19 @@ { "private": true, "scripts": { - "dev": "npm run development", - "development": "mix", - "watch": "mix watch", - "watch-poll": "mix watch -- --watch-options-poll=1000", - "hot": "mix watch --hot", - "prod": "npm run production", - "production": "mix --production" + "dev": "vite", + "build": "vite build" }, "devDependencies": { - "cross-env": "^7.0.3", - "laravel-mix": "^6.0.6", - "laravel-mix-merge-manifest": "^2.0.0", - "lodash": "^4.17.19", - "postcss": "^8.1.14", - "sass": "^1.32.8", - "sass-loader": "^11.0.1", - "vue": "^2.6.12", - "vue-loader": "^15.9.6", - "vue-template-compiler": "^2.6.12" + "autoprefixer": "^10.4.16", + "axios": "^1.6.4", + "laravel-vite-plugin": "^0.7.2", + "postcss": "^8.4.23", + "tailwindcss": "^3.3.2", + "vite": "^4.0.0", + "vue": "^3.4.19" }, "dependencies": { + "@vitejs/plugin-vue": "^4.2.3" } -} \ No newline at end of file + } \ No newline at end of file diff --git a/src/stubs/postcss.stub b/src/stubs/postcss.stub new file mode 100644 index 0000000..33ad091 --- /dev/null +++ b/src/stubs/postcss.stub @@ -0,0 +1,6 @@ +module.exports = { + plugins: { + tailwindcss: {}, + autoprefixer: {}, + }, +} diff --git a/src/stubs/request.stub b/src/stubs/request.stub index 7d527f1..dedcbc0 100644 --- a/src/stubs/request.stub +++ b/src/stubs/request.stub @@ -8,10 +8,8 @@ class $CLASS$ extends FormRequest { /** * Determine if the user is authorized to make this request. - * - * @return bool */ - public function authorize() + public function authorize(): bool { return false; } @@ -19,12 +17,12 @@ class $CLASS$ extends FormRequest /** * Get the validation rules that apply to the request. * - * @return array + * @return array|string> */ - public function rules() + public function rules(): array { return [ // ]; } -} \ No newline at end of file +} diff --git a/src/stubs/routes.stub b/src/stubs/routes.stub index 6bae5a1..a287731 100644 --- a/src/stubs/routes.stub +++ b/src/stubs/routes.stub @@ -1,10 +1,8 @@ 'admin/$LOWER_NAME$', - 'middleware' => ['web', 'user'] - ], function () { +use Illuminate\Support\Facades\Route; +use $CONTROLLER_CLASS_NAME$; - Route::get('', '$CONTROLLER_CLASS_NAME$@index')->name('admin.$LOWER_NAME$.index'); - -}); \ No newline at end of file +Route::prefix('$LOWER_NAME$')->group(function () { + Route::get('', [$CLASS_NAME$::class, 'index'])->name('admin.$LOWER_NAME$.index'); +}); diff --git a/src/stubs/scaffold/acl.stub b/src/stubs/scaffold/acl.stub index 9f813af..0974a33 100644 --- a/src/stubs/scaffold/acl.stub +++ b/src/stubs/scaffold/acl.stub @@ -2,9 +2,9 @@ return [ [ - 'key' => '$LOWER_NAME$', - 'name' => '$CAPITALIZE_NAME$', + 'key' => '$LOWER_NAME$', + 'name' => '$CAPITALIZE_NAME$', 'route' => 'admin.$LOWER_NAME$.index', - 'sort' => 2 + 'sort' => 2 ] -]; \ No newline at end of file +]; diff --git a/src/stubs/scaffold/menu.stub b/src/stubs/scaffold/menu.stub index b336947..6abdcd9 100644 --- a/src/stubs/scaffold/menu.stub +++ b/src/stubs/scaffold/menu.stub @@ -2,10 +2,10 @@ return [ [ - 'key' => '$LOWER_NAME$', - 'name' => '$CAPITALIZE_NAME$', - 'route' => 'admin.$LOWER_NAME$.index', - 'sort' => 2, + 'key' => '$LOWER_NAME$', + 'name' => '$CAPITALIZE_NAME$', + 'route' => 'admin.$LOWER_NAME$.index', + 'sort' => 2, 'icon-class' => 'temp-icon', ] -]; \ No newline at end of file +]; diff --git a/src/stubs/scaffold/module-provider.stub b/src/stubs/scaffold/module-provider.stub index 479972a..8c7f3a7 100644 --- a/src/stubs/scaffold/module-provider.stub +++ b/src/stubs/scaffold/module-provider.stub @@ -6,6 +6,12 @@ use Webkul\Core\Providers\BaseModuleServiceProvider; class ModuleServiceProvider extends BaseModuleServiceProvider { + /** + * The models to be used by this module. + * + * @var array + */ protected $models = [ + // ]; -} \ No newline at end of file +} diff --git a/src/stubs/scaffold/package-provider.stub b/src/stubs/scaffold/package-provider.stub index a1711b8..c1c065f 100755 --- a/src/stubs/scaffold/package-provider.stub +++ b/src/stubs/scaffold/package-provider.stub @@ -16,18 +16,14 @@ class $CLASS$ extends ServiceProvider { $this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations'); - $this->loadRoutesFrom(__DIR__ . '/../Http/routes.php'); + $this->loadRoutesFrom(__DIR__ . '/../Routes/web.php'); $this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', '$LOWER_NAME$'); - $this->publishes([ - __DIR__ . '/../../publishable/assets' => public_path('$LOWER_NAME$/assets'), - ], 'public'); - $this->loadViewsFrom(__DIR__ . '/../Resources/views', '$LOWER_NAME$'); - Event::listen('admin.layout.head', function($viewRenderEventManager) { - $viewRenderEventManager->addTemplate('$LOWER_NAME$::layouts.style'); + Event::listen('admin.layout.head.after', function($viewRenderEventManager) { + $viewRenderEventManager->addTemplate('$LOWER_NAME$::components.layouts.style'); }); } @@ -56,4 +52,4 @@ class $CLASS$ extends ServiceProvider dirname(__DIR__) . '/Config/acl.php', 'acl' ); } -} \ No newline at end of file +} diff --git a/src/stubs/tailwind.stub b/src/stubs/tailwind.stub new file mode 100644 index 0000000..cc19811 --- /dev/null +++ b/src/stubs/tailwind.stub @@ -0,0 +1,47 @@ +/** @type {import('tailwindcss').Config} */ +module.exports = { + content: ["./src/Resources/**/*.blade.php", "./src/Resources/**/*.js"], + + theme: { + container: { + center: true, + + screens: { + "2xl": "1920px", + }, + + padding: { + DEFAULT: "16px", + }, + }, + + screens: { + sm: "525px", + md: "768px", + lg: "1024px", + xl: "1240px", + "2xl": "1920px", + }, + + extend: { + colors: { + brandColor: '#0E90D9', + }, + + fontFamily: { + inter: ['Inter'], + icon: ['icomoon'] + } + }, + }, + + darkMode: 'class', + + plugins: [], + + safelist: [ + { + pattern: /icon-/, + } + ] +}; \ No newline at end of file diff --git a/src/stubs/views/components/layouts/style.stub b/src/stubs/views/components/layouts/style.stub new file mode 100644 index 0000000..b63fd0e --- /dev/null +++ b/src/stubs/views/components/layouts/style.stub @@ -0,0 +1,3 @@ +{{ + vite()->set(['src/Resources/assets/css/app.css', 'src/Resources/assets/js/app.js'], 'zoom_meeting') +}} diff --git a/src/stubs/views/index.stub b/src/stubs/views/index.stub index b187aaf..307ba67 100644 --- a/src/stubs/views/index.stub +++ b/src/stubs/views/index.stub @@ -1,23 +1,23 @@ -@extends('admin::layouts.master') + + + + Package $CAPITALIZE_NAME$ + -@section('page_title') - Package $CAPITALIZE_NAME$ -@stop + +
+
+
+
+ -@section('content-wrapper') +
-
- -
-
- -@stop \ No newline at end of file + diff --git a/src/stubs/views/layouts/style.stub b/src/stubs/views/layouts/style.stub deleted file mode 100644 index f055fd8..0000000 --- a/src/stubs/views/layouts/style.stub +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src/stubs/vite.stub b/src/stubs/vite.stub new file mode 100644 index 0000000..670f670 --- /dev/null +++ b/src/stubs/vite.stub @@ -0,0 +1,46 @@ +import { defineConfig, loadEnv } from "vite"; +import vue from "@vitejs/plugin-vue"; +import laravel from "laravel-vite-plugin"; +import path from "path"; + +export default defineConfig(({ mode }) => { + const envDir = "../../../"; + + Object.assign(process.env, loadEnv(mode, envDir)); + + return { + build: { + emptyOutDir: true, + }, + + envDir, + + server: { + host: process.env.VITE_HOST || "localhost", + port: process.env.VITE_PORT || 5174, + }, + + plugins: [ + vue(), + + laravel({ + hotFile: "../../../public/$LOWER_NAME$-vite.hot", + publicDirectory: "../../../public", + buildDirectory: "$LOWER_NAME$/build", + input: [ + "src/Resources/assets/css/app.css", + "src/Resources/assets/js/app.js", + ], + refresh: true, + }), + ], + + experimental: { + renderBuiltUrl(filename, { hostId, hostType, type }) { + if (hostType === "css") { + return path.basename(filename); + } + }, + }, + }; +}); \ No newline at end of file diff --git a/src/stubs/webpack.stub b/src/stubs/webpack.stub deleted file mode 100644 index 7666a41..0000000 --- a/src/stubs/webpack.stub +++ /dev/null @@ -1,39 +0,0 @@ -const mix = require("laravel-mix"); - -if (mix == 'undefined') { - const { mix } = require("laravel-mix"); -} - -require("laravel-mix-merge-manifest"); - -if (mix.inProduction()) { - var publicPath = 'publishable/assets'; -} else { - var publicPath = "../../../public/vendor/$LOWER_NAME$/assets"; -} - -mix.setPublicPath(publicPath).mergeManifest(); -mix.disableNotifications(); - -mix.js(__dirname + "/src/Resources/assets/js/app.js", "js/admin.js") - .copy(__dirname + "/src/Resources/assets/images", publicPath + "/images") - .sass(__dirname + "/src/Resources/assets/sass/app.scss", "css/admin.css") - .options({ - processCssUrls: false - }).vue(); - -mix.webpackConfig({ - resolve: { - alias: { - 'vue$': 'vue/dist/vue.runtime.js' - } - } -}); - -if (! mix.inProduction()) { - mix.sourceMaps(); -} - -if (mix.inProduction()) { - mix.version(); -} \ No newline at end of file