From c3c0f68121a7bcf9d4d9a182077695097525caf4 Mon Sep 17 00:00:00 2001 From: Shem Pasamba Date: Tue, 30 Jul 2019 17:45:55 +0800 Subject: [PATCH 1/7] Allow generation of files to a Module folder using --moduleName --- src/Commands/BaseCommand.php | 1 + src/Commands/RollbackGeneratorCommand.php | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Commands/BaseCommand.php b/src/Commands/BaseCommand.php index 3a15e86d9..ae09b1d66 100755 --- a/src/Commands/BaseCommand.php +++ b/src/Commands/BaseCommand.php @@ -253,6 +253,7 @@ public function getOptions() ['relations', null, InputOption::VALUE_NONE, 'Specify if you want to pass relationships for fields'], ['softDelete', null, InputOption::VALUE_NONE, 'Soft Delete Option'], ['forceMigrate', null, InputOption::VALUE_NONE, 'Specify if you want to run migration or not'], + ['moduleName', null, InputOption::VALUE_REQUIRED, 'Generate files to this module & namespace (eg. Admin)'], ]; } diff --git a/src/Commands/RollbackGeneratorCommand.php b/src/Commands/RollbackGeneratorCommand.php index 2b830c0ef..f5cb4ea60 100755 --- a/src/Commands/RollbackGeneratorCommand.php +++ b/src/Commands/RollbackGeneratorCommand.php @@ -77,10 +77,11 @@ public function handle() $this->error('invalid rollback type'); } + $this->commandData = new CommandData($this, $this->argument('type')); $this->commandData->config->mName = $this->commandData->modelName = $this->argument('model'); - $this->commandData->config->init($this->commandData, ['tableName', 'prefix', 'plural']); + $this->commandData->config->init($this->commandData, ['tableName', 'prefix', 'plural', 'moduleName']); $migrationGenerator = new MigrationGenerator($this->commandData); $migrationGenerator->rollback(); @@ -155,6 +156,7 @@ public function getOptions() ['tableName', null, InputOption::VALUE_REQUIRED, 'Table Name'], ['prefix', null, InputOption::VALUE_REQUIRED, 'Prefix for all files'], ['plural', null, InputOption::VALUE_REQUIRED, 'Plural Model name'], + ['moduleName', null, InputOption::VALUE_REQUIRED, 'Generate files to this module & namespace (eg. Admin)'], ]; } From d9df52d3b11f4c148996d5db5c71372d2ae09834 Mon Sep 17 00:00:00 2001 From: Shem Pasamba Date: Tue, 30 Jul 2019 18:13:29 +0800 Subject: [PATCH 2/7] Here's the real enabler of --moduleName --- src/Common/GeneratorConfig.php | 48 ++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/Common/GeneratorConfig.php b/src/Common/GeneratorConfig.php index 767d8da67..d85235bfe 100755 --- a/src/Common/GeneratorConfig.php +++ b/src/Common/GeneratorConfig.php @@ -353,6 +353,54 @@ public function prepareOptions(CommandData &$commandData) $this->addOns['datatables'] = false; } } + if (!empty($this->options['moduleName'])) { + if (!file_exists(config_path('modules.php'))) { + $commandData->commandError('Can\'t use modules since config doesn\'t exist in '.config_path('modules.php').'.'); + exit; + } + // change folder locations + $this->modules_path = config('modules.paths.modules', base_path('Modules')).'/'.$this->options['moduleName']; + $config_paths = config('infyom.laravel_generator.path'); + $new_config_paths = []; + foreach($config_paths as $key => $path) { + if (preg_match('/migrations/', $path)) + $path = str_replace('migrations', 'Migrations', $path); + if (strpos($path, app_path()) === 0) { + $new_config_paths[$key] = str_replace(app_path(), $this->modules_path, $path); + } else { + $new_config_paths[$key] = str_replace(base_path(), $this->modules_path, $path); + } + $new_config_paths[$key][strlen($this->modules_path)+1] = strtoupper($new_config_paths[$key][strlen($this->modules_path)+1]); + } + config(['infyom.laravel_generator.path' => $new_config_paths]); + + // change namespace + $this->module_namespace = config('modules.namespace', 'Modules').'\\'.$this->options['moduleName'].'\\'; + $config_namespaces = config('infyom.laravel_generator.namespace'); + $new_config_namespaces = []; + foreach($config_namespaces as $key => $namespace) + { + if (strpos($namespace, 'App\\') === 0) + $namespace = str_replace('App\\', '', $namespace); + $new_config_namespaces[$key] = $this->module_namespace.$namespace; + } + config(['infyom.laravel_generator.namespace' => $new_config_namespaces]); + + // change prefix + $viewPrefix = $this->prefixes['view']; + config(['infyom.laravel_generator.prefixes.view' => strtolower($this->options['moduleName']).'::']); + $this->prefixes['view'] = config('infyom.laravel_generator.prefixes.view'); + if ($this->getOption('plural')) { + $this->mPlural = $this->getOption('plural'); + } else { + $this->mPlural = Str::plural($this->mName); + } + $this->mSnakePlural = Str::snake($this->mPlural); + $this->pathViews = config( + 'infyom.laravel_generator.path.views', + base_path('resources/views/') + ).$viewPrefix.$this->mSnakePlural.'/'; + } } public function preparePrefixes() From 75883132e0ccd55e3fa79d83da9701b0fdc1c883 Mon Sep 17 00:00:00 2001 From: Shem Pasamba Date: Tue, 30 Jul 2019 18:14:47 +0800 Subject: [PATCH 3/7] Remove added extra space --- src/Commands/RollbackGeneratorCommand.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Commands/RollbackGeneratorCommand.php b/src/Commands/RollbackGeneratorCommand.php index f5cb4ea60..ca86a8117 100755 --- a/src/Commands/RollbackGeneratorCommand.php +++ b/src/Commands/RollbackGeneratorCommand.php @@ -77,7 +77,6 @@ public function handle() $this->error('invalid rollback type'); } - $this->commandData = new CommandData($this, $this->argument('type')); $this->commandData->config->mName = $this->commandData->modelName = $this->argument('model'); From d3a52ea5399ded956f5432c85f6dbe610719ab9f Mon Sep 17 00:00:00 2001 From: Shem Pasamba Date: Tue, 30 Jul 2019 18:19:11 +0800 Subject: [PATCH 4/7] style fixes --- src/Common/GeneratorConfig.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Common/GeneratorConfig.php b/src/Common/GeneratorConfig.php index d85235bfe..f93f21925 100755 --- a/src/Common/GeneratorConfig.php +++ b/src/Common/GeneratorConfig.php @@ -362,15 +362,16 @@ public function prepareOptions(CommandData &$commandData) $this->modules_path = config('modules.paths.modules', base_path('Modules')).'/'.$this->options['moduleName']; $config_paths = config('infyom.laravel_generator.path'); $new_config_paths = []; - foreach($config_paths as $key => $path) { - if (preg_match('/migrations/', $path)) + foreach ($config_paths as $key => $path) { + if (preg_match('/migrations/', $path)) { $path = str_replace('migrations', 'Migrations', $path); + } if (strpos($path, app_path()) === 0) { $new_config_paths[$key] = str_replace(app_path(), $this->modules_path, $path); } else { $new_config_paths[$key] = str_replace(base_path(), $this->modules_path, $path); } - $new_config_paths[$key][strlen($this->modules_path)+1] = strtoupper($new_config_paths[$key][strlen($this->modules_path)+1]); + $new_config_paths[$key][strlen($this->modules_path) + 1] = strtoupper($new_config_paths[$key][strlen($this->modules_path) + 1]); } config(['infyom.laravel_generator.path' => $new_config_paths]); @@ -378,10 +379,10 @@ public function prepareOptions(CommandData &$commandData) $this->module_namespace = config('modules.namespace', 'Modules').'\\'.$this->options['moduleName'].'\\'; $config_namespaces = config('infyom.laravel_generator.namespace'); $new_config_namespaces = []; - foreach($config_namespaces as $key => $namespace) - { - if (strpos($namespace, 'App\\') === 0) + foreach ($config_namespaces as $key => $namespace) { + if (strpos($namespace, 'App\\') === 0) { $namespace = str_replace('App\\', '', $namespace); + } $new_config_namespaces[$key] = $this->module_namespace.$namespace; } config(['infyom.laravel_generator.namespace' => $new_config_namespaces]); From 2b50b59ba515803ade8aac34cc6ef2d3e1a59b33 Mon Sep 17 00:00:00 2001 From: Shem Pasamba Date: Tue, 1 Oct 2019 10:53:43 +0800 Subject: [PATCH 5/7] fixes to actually show option --- src/Commands/BaseCommand.php | 1 + src/Common/GeneratorConfig.php | 1 + src/Common/GeneratorField.php | 1 - src/Generators/Scaffold/MenuGenerator.php | 17 ++++++++++++++--- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Commands/BaseCommand.php b/src/Commands/BaseCommand.php index 09490da1d..82120dbf0 100755 --- a/src/Commands/BaseCommand.php +++ b/src/Commands/BaseCommand.php @@ -270,6 +270,7 @@ public function getOptions() ['factory', null, InputOption::VALUE_NONE, 'To generate factory'], ['seeder', null, InputOption::VALUE_NONE, 'To generate seeder'], ['repositoryPattern', null, InputOption::VALUE_REQUIRED, 'Repository Pattern'], + ['moduleName', null, InputOption::VALUE_REQUIRED, 'Generate files to this module & namespace (eg. Admin)'], ]; } diff --git a/src/Common/GeneratorConfig.php b/src/Common/GeneratorConfig.php index aa162dfe3..2282486bd 100755 --- a/src/Common/GeneratorConfig.php +++ b/src/Common/GeneratorConfig.php @@ -88,6 +88,7 @@ class GeneratorConfig 'factory', 'seeder', 'repositoryPattern', + 'moduleName', ]; public $tableName; diff --git a/src/Common/GeneratorField.php b/src/Common/GeneratorField.php index 5ef7e5dbc..536d997c1 100644 --- a/src/Common/GeneratorField.php +++ b/src/Common/GeneratorField.php @@ -29,7 +29,6 @@ class GeneratorField public $inForm = true; public $inIndex = true; public $inView = true; - public $isNotNull = false; /** * @param Column $column diff --git a/src/Generators/Scaffold/MenuGenerator.php b/src/Generators/Scaffold/MenuGenerator.php index a76d059e5..cad20f27a 100755 --- a/src/Generators/Scaffold/MenuGenerator.php +++ b/src/Generators/Scaffold/MenuGenerator.php @@ -23,6 +23,9 @@ class MenuGenerator extends BaseGenerator /** @var string */ private $menuTemplate; + /** @var boolean */ + private $dontGenerateMenu; + public function __construct(CommandData $commandData) { $this->commandData = $commandData; @@ -33,15 +36,23 @@ public function __construct(CommandData $commandData) ).$commandData->getAddOn('menu.menu_file'); $this->templateType = config('infyom.laravel_generator.templates', 'adminlte-templates'); - $this->menuContents = file_get_contents($this->path); + if (!file_exists($this->path)) + $this->dontGenerateMenu = true; + else + { + $this->menuContents = file_get_contents($this->path); - $this->menuTemplate = get_template('scaffold.layouts.menu_template', $this->templateType); + $this->menuTemplate = get_template('scaffold.layouts.menu_template', $this->templateType); - $this->menuTemplate = fill_template($this->commandData->dynamicVars, $this->menuTemplate); + $this->menuTemplate = fill_template($this->commandData->dynamicVars, $this->menuTemplate); + } } public function generate() { + if ($this->dontGenerateMenu) + return true; + $this->menuContents .= $this->menuTemplate.infy_nl(); file_put_contents($this->path, $this->menuContents); From ed925b5a5c5cd90c127fb540e13faa732d52d78d Mon Sep 17 00:00:00 2001 From: Shem Pasamba Date: Tue, 1 Oct 2019 13:25:28 +0800 Subject: [PATCH 6/7] allow relations names that includes schema --- src/Common/GeneratorFieldRelation.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Common/GeneratorFieldRelation.php b/src/Common/GeneratorFieldRelation.php index dba27ec3f..ecb8890d9 100644 --- a/src/Common/GeneratorFieldRelation.php +++ b/src/Common/GeneratorFieldRelation.php @@ -29,6 +29,7 @@ public static function parseRelation($relationInput) public function getRelationFunctionText($relationText = null) { + $relationText = str_replace(".", "_", $relationText); $singularRelation = (!empty($this->relationName)) ? $this->relationName : Str::camel($relationText); $pluralRelation = (!empty($this->relationName)) ? $this->relationName : Str::camel(Str::plural($relationText)); From 97a7d23eb1d006c50dfcd66b474b5b122367c71b Mon Sep 17 00:00:00 2001 From: Shem Pasamba Date: Wed, 5 Feb 2020 18:20:59 +0800 Subject: [PATCH 7/7] style fixes --- src/Common/GeneratorFieldRelation.php | 2 +- src/Generators/Scaffold/MenuGenerator.php | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Common/GeneratorFieldRelation.php b/src/Common/GeneratorFieldRelation.php index ecb8890d9..9729564ad 100644 --- a/src/Common/GeneratorFieldRelation.php +++ b/src/Common/GeneratorFieldRelation.php @@ -29,7 +29,7 @@ public static function parseRelation($relationInput) public function getRelationFunctionText($relationText = null) { - $relationText = str_replace(".", "_", $relationText); + $relationText = str_replace('.', '_', $relationText); $singularRelation = (!empty($this->relationName)) ? $this->relationName : Str::camel($relationText); $pluralRelation = (!empty($this->relationName)) ? $this->relationName : Str::camel(Str::plural($relationText)); diff --git a/src/Generators/Scaffold/MenuGenerator.php b/src/Generators/Scaffold/MenuGenerator.php index 4148f0825..964b90128 100755 --- a/src/Generators/Scaffold/MenuGenerator.php +++ b/src/Generators/Scaffold/MenuGenerator.php @@ -23,7 +23,7 @@ class MenuGenerator extends BaseGenerator /** @var string */ private $menuTemplate; - /** @var boolean */ + /** @var bool */ private $dontGenerateMenu; public function __construct(CommandData $commandData) @@ -36,10 +36,9 @@ public function __construct(CommandData $commandData) ).$commandData->getAddOn('menu.menu_file'); $this->templateType = config('infyom.laravel_generator.templates', 'adminlte-templates'); - if (!file_exists($this->path)) + if (!file_exists($this->path)) { $this->dontGenerateMenu = true; - else - { + } else { $this->menuContents = file_get_contents($this->path); $templateName = 'menu_template'; @@ -56,8 +55,9 @@ public function __construct(CommandData $commandData) public function generate() { - if ($this->dontGenerateMenu) + if ($this->dontGenerateMenu) { return true; + } $this->menuContents .= $this->menuTemplate.infy_nl(); $existingMenuContents = file_get_contents($this->path);