¨4.0.1¨

This commit is contained in:
¨NW¨
2023-12-03 14:07:47 +00:00
parent c08b36d1b6
commit f35052522d
1112 changed files with 43019 additions and 24987 deletions

View File

@@ -18,14 +18,16 @@ class EntityGenerator extends Generator
'views/shortcuts.stub' => 'Resources/views/admin/$ENTITY_NAME$/partials/shortcuts.blade.php',
];
/**
* Generate the given entities.
*
* @param array $entities
* @param bool $generateSidebar
*
* @return void
*/
public function generate(array $entities, $generateSidebar = true)
public function generate(array $entities, $generateSidebar = true): void
{
if (count($entities) !== 0 && $generateSidebar) {
$this->generateSidebarExtender($entities);
@@ -44,11 +46,13 @@ class EntityGenerator extends Generator
}
}
/**
* Generate a filled sidebar view composer
* Or an empty one of no entities.
*
* @param $entities
*
* @return void
*/
private function generateSidebarExtender($entities)
@@ -59,10 +63,12 @@ class EntityGenerator extends Generator
);
}
/**
* Append permissions.
*
* @param string $entity
*
* @return void
*/
private function appendPermissions($entity)
@@ -75,10 +81,12 @@ class EntityGenerator extends Generator
);
}
/**
* Generate migrations file for eloquent entities.
*
* @param string $entity
*
* @return void
*/
private function generateMigrations($entity)
@@ -99,6 +107,7 @@ class EntityGenerator extends Generator
);
}
/**
* Get the current time with microseconds.
*
@@ -114,10 +123,12 @@ class EntityGenerator extends Generator
return $date->format('Y_m_d_Hisu_');
}
/**
* Generate entity.
*
* @param string $entity
*
* @return void
*/
private function generateEntity($entity)
@@ -133,10 +144,12 @@ class EntityGenerator extends Generator
);
}
/**
* Generate the controller for the given entity.
*
* @param string $entity
*
* @return void
*/
private function generateController($entity)
@@ -149,10 +162,12 @@ class EntityGenerator extends Generator
);
}
/**
* Generate the requests for the given entity.
*
* @param string $entity
*
* @return void
*/
private function generateRequests($entity)
@@ -165,32 +180,12 @@ class EntityGenerator extends Generator
);
}
/**
* Generate views for the given entity.
*
* @param string $entity
* @return void
*/
private function generateViews($entity)
{
$entityName = snake_case(str_plural($entity));
$this->createDirectory("Resources/views/admin/{$entityName}/partials");
foreach ($this->views as $stub => $view) {
$view = str_replace('$ENTITY_NAME$', $entityName, $view);
$this->finder->put(
$this->getModulesPath($view),
$this->getContentForStub($stub, $entity)
);
}
}
/**
* Generate language files for the given entity.
*
* @param string $entity
*
* @return void
*/
private function generateLang($entity)
@@ -215,10 +210,36 @@ class EntityGenerator extends Generator
);
}
/**
* Generate views for the given entity.
*
* @param string $entity
*
* @return void
*/
private function generateViews($entity)
{
$entityName = snake_case(str_plural($entity));
$this->createDirectory("Resources/views/admin/{$entityName}/partials");
foreach ($this->views as $stub => $view) {
$view = str_replace('$ENTITY_NAME$', $entityName, $view);
$this->finder->put(
$this->getModulesPath($view),
$this->getContentForStub($stub, $entity)
);
}
}
/**
* Append the routes for the given entity to the routes file.
*
* @param string $entity
*
* @return void
*/
private function appendRoutes($entity)
@@ -231,10 +252,12 @@ class EntityGenerator extends Generator
);
}
/**
* Append sidebar extender.
*
* @param string $entity
*
* @return void
*/
private function appendSidebarExtender($entity)

View File

@@ -9,10 +9,12 @@ class FilesGenerator extends Generator
/**
* Generate the given files.
*
* @param array $files
* @param array $files
*
* @return void
* @throws FileNotFoundException
*/
public function generate(array $files)
public function generate(array $files): void
{
foreach ($files as $stub => $file) {
$this->finder->put(
@@ -22,30 +24,32 @@ class FilesGenerator extends Generator
}
}
/**
* Generate the base module service provider.
*
* @return $this
* @return void
* @throws FileNotFoundException
*/
public function generateModuleProvider()
public function generateModuleServiceProvider(): void
{
$this->finder->put(
$this->getModulesPath("Providers/{$this->name}ServiceProvider.php"),
$this->getContentFor('providers/module-service-provider.stub')
);
return $this;
}
/**
* Get the content for the given file.
*
* @param string $stub
*
* @return string
*
* @throws FileNotFoundException
*/
private function getContentFor($stub)
private function getContentFor(string $stub): string
{
$stub = $this->finder->get($this->getStubPath($stub));

View File

@@ -3,101 +3,103 @@
namespace FleetCart\Scaffold\Module\Generators;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
abstract class Generator
{
/**
* The instance of Filesystem.
*
* @var \Illuminate\Filesystem\Filesystem
* @var Filesystem
*/
protected $finder;
protected Filesystem $finder;
/**
* Name of the module.
*
* @var string
*/
protected $name;
protected string $name;
/**
* Create a new instance.
*
* @param \Illuminate\Filesystem\Filesystem $finder
* @param Filesystem $finder
*/
public function __construct(Filesystem $finder)
{
$this->finder = $finder;
}
/**
* Generate the given files.
*
* @param array $files
*
* @return void
*/
abstract public function generate(array $files);
abstract public function generate(array $files): void;
/**
* Set the module name.
*
* @param string $name
*
* @return $this
*/
public function module($name)
public function module(string $name): static
{
$this->name = ucfirst($name);
return $this;
}
/**
* Return the current module path.
*
* @param string $path
* @return string
*/
protected function getModulesPath($path = '')
{
return config('modules.paths.modules') . "/{$this->name}/{$path}";
}
/**
* Create directory if not exists.
*
* @param string $path
*
* @return string
*/
protected function createDirectory($path)
protected function createDirectory($path): string
{
$path = $this->getModulesPath($path);
if (! $this->finder->isDirectory($path)) {
if (!$this->finder->isDirectory($path)) {
$this->finder->makeDirectory($path, 0755, true);
}
return $path;
}
/**
* Get stub path for the given stub file.
* Return the current module path.
*
* @param string $path
*
* @param string $filename
* @return string
*/
protected function getStubPath($filename)
protected function getModulesPath(string $path = ''): string
{
return __DIR__ . "/../stubs/{$filename}";
return config('modules.paths.modules') . "/{$this->name}/{$path}";
}
/**
* Get content of the given stub.
*
* @param string $stub
* @param string $class
*
* @return string
* @throws FileNotFoundException
*/
protected function getContentForStub($stub, $class = '')
protected function getContentForStub(string $stub, string $class = ''): string
{
$stub = $this->finder->get($this->getStubPath($stub));
@@ -131,4 +133,17 @@ abstract class Generator
kebab_case(str_plural($class)),
], $stub);
}
/**
* Get stub path for the given stub file.
*
* @param string $filename
*
* @return string
*/
protected function getStubPath($filename)
{
return __DIR__ . "/../stubs/{$filename}";
}
}