¨4.0.1¨
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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));
|
||||
|
||||
|
||||
@@ -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}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use Illuminate\Filesystem\Filesystem;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use FleetCart\Scaffold\Module\Generators\FilesGenerator;
|
||||
use FleetCart\Scaffold\Module\Generators\EntityGenerator;
|
||||
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
||||
|
||||
class ModuleScaffold
|
||||
{
|
||||
@@ -14,53 +15,49 @@ class ModuleScaffold
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $vendor;
|
||||
protected string $vendor;
|
||||
|
||||
/**
|
||||
* The module name which will be generated.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* The instance of Filesystem.
|
||||
*
|
||||
* @var \Illuminate\Filesystem\Filesystem
|
||||
*/
|
||||
private $finder;
|
||||
|
||||
/**
|
||||
* The instance of EntityGenerator.
|
||||
*
|
||||
* @var \FleetCart\Scaffold\Module\Generators\EntityGenerator
|
||||
*/
|
||||
private $entityGenerator;
|
||||
|
||||
/**
|
||||
* The instance of FilesGenerator.
|
||||
*
|
||||
* @var \FleetCart\Scaffold\Module\Generators\FilesGenerator
|
||||
*/
|
||||
private $filesGenerator;
|
||||
|
||||
protected string $name;
|
||||
/**
|
||||
* Array of files to be generated.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $files = [
|
||||
'config/assets.stub' => 'Config/assets.php',
|
||||
protected array $stubsToFilesMap = [
|
||||
'config/permissions.stub' => 'Config/permissions.php',
|
||||
'routes/routes.stub' => 'Routes/admin.php',
|
||||
];
|
||||
/**
|
||||
* The instance of Filesystem.
|
||||
*
|
||||
* @var Filesystem
|
||||
*/
|
||||
private Filesystem $finder;
|
||||
/**
|
||||
* The instance of EntityGenerator.
|
||||
*
|
||||
* @var EntityGenerator
|
||||
*/
|
||||
private EntityGenerator $entityGenerator;
|
||||
/**
|
||||
* The instance of FilesGenerator.
|
||||
*
|
||||
* @var FilesGenerator
|
||||
*/
|
||||
private FilesGenerator $filesGenerator;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param \Illuminate\Filesystem\Filesystem $finder
|
||||
* @param \FleetCart\Scaffold\Module\Generators\EntityGenerator $entityGenerator
|
||||
* @param \FleetCart\Scaffold\Module\Generators\FilesGenerator $filesGenerator
|
||||
* @param Filesystem $finder
|
||||
* @param EntityGenerator $entityGenerator
|
||||
* @param FilesGenerator $filesGenerator
|
||||
*/
|
||||
public function __construct(Filesystem $finder, EntityGenerator $entityGenerator, FilesGenerator $filesGenerator)
|
||||
{
|
||||
@@ -69,124 +66,129 @@ class ModuleScaffold
|
||||
$this->filesGenerator = $filesGenerator;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $module
|
||||
* @param array $entities
|
||||
*
|
||||
* @return void
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
public function scaffold(array $module, array $entities)
|
||||
public function scaffold(array $module, array $entities): void
|
||||
{
|
||||
$this->vendor = $module['vendor'];
|
||||
$this->name = $module['name'];
|
||||
|
||||
Artisan::call('module:make', ['name' => [$this->name]]);
|
||||
|
||||
$this->generateModule();
|
||||
$this->renameVendorName();
|
||||
$this->addFolders();
|
||||
$this->removeUnneededFiles();
|
||||
$this->addDataToComposerJsonFile();
|
||||
$this->removeUnneededFilesAndFolders();
|
||||
$this->modifyComposerJsonFile();
|
||||
|
||||
$this->filesGenerator->module($this->name)
|
||||
->generateModuleProvider()
|
||||
->generate($this->files);
|
||||
$this->filesGenerator->module($this->name)->generateModuleServiceProvider();
|
||||
$this->filesGenerator->module($this->name)->generate($this->stubsToFilesMap);
|
||||
|
||||
$this->addDataToModuleJson();
|
||||
$this->modifyModuleJsonFile();
|
||||
$this->cleanupModuleJsonFile();
|
||||
|
||||
$this->entityGenerator->module($this->getName())->generate($entities);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate default module.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function generateModule(): void
|
||||
{
|
||||
Artisan::call('module:make', ['name' => [$this->name]]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get studly cased module name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
public function getName(): string
|
||||
{
|
||||
return studly_case($this->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path on the module.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getModulesPath($path = '')
|
||||
{
|
||||
return config('modules.paths.modules') . "/{$this->getName()}/{$path}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the paths on the module.
|
||||
*
|
||||
* @param array $paths
|
||||
* @return array
|
||||
*/
|
||||
private function getModulesPaths(array $paths)
|
||||
{
|
||||
$list = [];
|
||||
|
||||
foreach ($paths as $path) {
|
||||
$list[] = $this->getModulesPath($path);
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove vendor name from composer.json file.
|
||||
*
|
||||
* @return void
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
private function renameVendorName()
|
||||
private function renameVendorName(): void
|
||||
{
|
||||
$composerJsonContent = $this->finder->get($this->getModulesPath('composer.json'));
|
||||
$composerJsonPath = $this->getModulesPath('composer.json');
|
||||
$composerJsonContent = $this->finder->get($composerJsonPath);
|
||||
$composerJsonContent = str_replace('nwidart', $this->vendor, $composerJsonContent);
|
||||
|
||||
$this->finder->put($this->getModulesPath('composer.json'), $composerJsonContent);
|
||||
$this->finder->put($composerJsonPath, $composerJsonContent);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove view files.
|
||||
* Get the path on the module.
|
||||
*
|
||||
* @return void
|
||||
* @param string $path
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function removeViewFiles()
|
||||
private function getModulesPath(string $path = ''): string
|
||||
{
|
||||
$this->finder->delete($this->getModulesPath('Resources/views/index.blade.php'));
|
||||
$this->finder->delete($this->getModulesPath('Resources/views/layouts/master.blade.php'));
|
||||
$this->finder->deleteDirectory($this->getModulesPath('Resources/views/layouts'));
|
||||
return config('modules.paths.modules') . "/{$this->getName()}/{$path}";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add required folders.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function addFolders()
|
||||
private function addFolders(): void
|
||||
{
|
||||
$this->finder->makeDirectory($this->getModulesPath('Sidebar'));
|
||||
$this->addSidebarFolder();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add Sidebar folder.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function addSidebarFolder(): void
|
||||
{
|
||||
$directoryPath = $this->getModulesPath('Sidebar');
|
||||
$this->finder->makeDirectory($directoryPath);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove unneeded files and folders.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function removeUnneededFiles()
|
||||
private function removeUnneededFilesAndFolders(): void
|
||||
{
|
||||
$this->renameVendorName();
|
||||
$this->removeViewFiles();
|
||||
$this->removeUnneededFiles();
|
||||
$this->removeUnneededFolders();
|
||||
}
|
||||
|
||||
$this->finder->deleteDirectory($this->getModulesPath('Database/factories'));
|
||||
$this->finder->deleteDirectory($this->getModulesPath('Database/Seeders'));
|
||||
$this->finder->deleteDirectory($this->getModulesPath('Events'));
|
||||
$this->finder->deleteDirectory($this->getModulesPath('Console'));
|
||||
$this->finder->deleteDirectory($this->getModulesPath('Http/Middleware'));
|
||||
$this->finder->deleteDirectory($this->getModulesPath('Jobs'));
|
||||
$this->finder->deleteDirectory($this->getModulesPath('Mail'));
|
||||
$this->finder->deleteDirectory($this->getModulesPath('Resources/assets'));
|
||||
$this->finder->deleteDirectory($this->getModulesPath('Tests'));
|
||||
|
||||
/**
|
||||
* Remove unneeded files.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function removeUnneededFiles(): void
|
||||
{
|
||||
$files = $this->getModulesPaths([
|
||||
'Config/.gitkeep',
|
||||
'Config/config.php',
|
||||
@@ -199,6 +201,8 @@ class ModuleScaffold
|
||||
'Providers/RouteServiceProvider.php',
|
||||
'Resources/lang/.gitkeep',
|
||||
'Resources/views/.gitkeep',
|
||||
'Resources/views/index.blade.php',
|
||||
'Resources/views/layouts/master.blade.php',
|
||||
'Routes/.gitkeep',
|
||||
'Routes/web.php',
|
||||
'Routes/api.php',
|
||||
@@ -209,12 +213,116 @@ class ModuleScaffold
|
||||
$this->finder->delete($files);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the paths on the module.
|
||||
*
|
||||
* @param array $paths
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getModulesPaths(array $paths): array
|
||||
{
|
||||
$list = [];
|
||||
|
||||
foreach ($paths as $path) {
|
||||
$list[] = $this->getModulesPath($path);
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove unneeded folders.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function removeUnneededFolders(): void
|
||||
{
|
||||
$this->finder->deleteDirectory($this->getModulesPath('Database/factories'));
|
||||
$this->finder->deleteDirectory($this->getModulesPath('Database/Seeders'));
|
||||
$this->finder->deleteDirectory($this->getModulesPath('Events'));
|
||||
$this->finder->deleteDirectory($this->getModulesPath('Console'));
|
||||
$this->finder->deleteDirectory($this->getModulesPath('Http/Middleware'));
|
||||
$this->finder->deleteDirectory($this->getModulesPath('Jobs'));
|
||||
$this->finder->deleteDirectory($this->getModulesPath('Mail'));
|
||||
$this->finder->deleteDirectory($this->getModulesPath('Resources/assets'));
|
||||
$this->finder->deleteDirectory($this->getModulesPath('Resources/views/layouts'));
|
||||
$this->finder->deleteDirectory($this->getModulesPath('Tests'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add data to composer.json file.
|
||||
*
|
||||
* @return void
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
private function modifyComposerJsonFile(): void
|
||||
{
|
||||
$moduleName = ucfirst($this->name);
|
||||
$composerJsonPath = $this->getModulesPath('composer.json');
|
||||
|
||||
$composerJsonFile = fopen($composerJsonPath, "r");
|
||||
|
||||
$composerJsonFileAsArray = [];
|
||||
while (!feof($composerJsonFile)) {
|
||||
$composerJsonFileAsArray[] = rtrim(fgets($composerJsonFile));
|
||||
}
|
||||
|
||||
$composerJsonText = '';
|
||||
|
||||
foreach ($composerJsonFileAsArray as $lineNumber => $textLine) {
|
||||
if ($lineNumber === 2) {
|
||||
$composerJsonText .= " \"description\": \"The FleetCart {$moduleName} Module.\"," . PHP_EOL;
|
||||
continue;
|
||||
} else if ($lineNumber >= 9 && $lineNumber <= 23) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$composerJsonText .= $textLine . PHP_EOL;
|
||||
}
|
||||
|
||||
$search = <<<JSON
|
||||
],
|
||||
JSON;
|
||||
|
||||
$replace = <<<JSON
|
||||
],
|
||||
"require": {
|
||||
"php": ">=8.0.2"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Modules\\\\{$moduleName}\\\\": ""
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"sort-packages": true
|
||||
},
|
||||
"minimum-stability": "dev"
|
||||
}
|
||||
JSON;
|
||||
|
||||
$composerJson = str_replace($search, $replace, $composerJsonText);
|
||||
|
||||
$this->finder->put($this->getModulesPath('composer.json'), $composerJson);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add data to module.json file.
|
||||
*
|
||||
* @return void
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
private function addDataToModuleJson()
|
||||
private function modifyModuleJsonFile(): void
|
||||
{
|
||||
$moduleJson = $this->finder->get($this->getModulesPath('module.json'));
|
||||
|
||||
@@ -223,22 +331,27 @@ class ModuleScaffold
|
||||
$this->finder->put($this->getModulesPath('module.json'), $moduleJson);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the module priority for composer.json file.
|
||||
*
|
||||
* @param $content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function setModulePriority($content)
|
||||
private function setModulePriority($content): string
|
||||
{
|
||||
return str_replace('"priority": 0,', '"priority": 100,', $content);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove unneeded data from module.json file.
|
||||
*
|
||||
* @return void
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
private function cleanupModuleJsonFile()
|
||||
private function cleanupModuleJsonFile(): void
|
||||
{
|
||||
$moduleJson = $this->finder->get($this->getModulesPath('module.json'));
|
||||
|
||||
@@ -274,60 +387,4 @@ JSON;
|
||||
|
||||
$this->finder->put($this->getModulesPath('module.json'), $moduleJson);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add data to composer.json file.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function addDataToComposerJsonFile()
|
||||
{
|
||||
$composerJson = $this->finder->get($this->getModulesPath('composer.json'));
|
||||
|
||||
$moduleName = ucfirst($this->name);
|
||||
|
||||
$composerJsonText = '';
|
||||
|
||||
foreach (explode(PHP_EOL, $composerJson) as $lineNumber => $textLine) {
|
||||
if ($lineNumber === 2) {
|
||||
$composerJsonText .= " \"description\": \"The FleetCart {$moduleName} Module.\"," . PHP_EOL;
|
||||
|
||||
continue;
|
||||
} elseif ($lineNumber >= 9 && $lineNumber <= 23) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$composerJsonText .= $textLine . PHP_EOL;
|
||||
}
|
||||
|
||||
$search = <<<JSON
|
||||
],
|
||||
JSON;
|
||||
|
||||
$replace = <<<JSON
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.3.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Modules\\\\{$moduleName}\\\\": ""
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"sort-packages": true
|
||||
},
|
||||
"minimum-stability": "dev"
|
||||
}
|
||||
JSON;
|
||||
|
||||
$composerJson = str_replace($search, $replace, $composerJsonText);
|
||||
|
||||
$this->finder->put($this->getModulesPath('composer.json'), $composerJson);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,10 @@
|
||||
|
||||
namespace Modules\$MODULE$\Providers;
|
||||
|
||||
use Modules\Support\Traits\AddsAsset;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class $MODULE$ServiceProvider extends ServiceProvider
|
||||
{
|
||||
use AddsAsset;
|
||||
|
||||
/**
|
||||
* Bootstrap the application services.
|
||||
*
|
||||
|
||||
@@ -14,3 +14,10 @@
|
||||
@endsection
|
||||
|
||||
@include('$LOWERCASE_MODULE_NAME$::admin.$PLURAL_SNAKE_CASE_ENTITY_NAME$.partials.shortcuts')
|
||||
|
||||
@push('globals')
|
||||
@vite([
|
||||
'Modules/Variation/Resources/assets/admin/sass/main.scss',
|
||||
'Modules/Variation/Resources/assets/admin/js/main.js',
|
||||
])
|
||||
@endpush
|
||||
|
||||
@@ -16,3 +16,10 @@
|
||||
@endsection
|
||||
|
||||
@include('$LOWERCASE_MODULE_NAME$::admin.$PLURAL_SNAKE_CASE_ENTITY_NAME$.partials.shortcuts')
|
||||
|
||||
@push('globals')
|
||||
@vite([
|
||||
'Modules/Variation/Resources/assets/admin/sass/main.scss',
|
||||
'Modules/Variation/Resources/assets/admin/js/main.js',
|
||||
])
|
||||
@endpush
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
@endcomponent
|
||||
|
||||
@push('scripts')
|
||||
<script>
|
||||
<script type="module">
|
||||
new DataTable('#$PLURAL_SNAKE_CASE_ENTITY_NAME$-table .table', {
|
||||
columns: [
|
||||
{ data: 'checkbox', orderable: false, searchable: false, width: '3%' },
|
||||
|
||||
Reference in New Issue
Block a user