Skip to content

Commit

Permalink
Merge pull request #9 from tomatophp/develop
Browse files Browse the repository at this point in the history
add new commands and fix old commands
  • Loading branch information
3x1io authored Feb 21, 2024
2 parents 2231f74 + eae8558 commit 5f7e59e
Show file tree
Hide file tree
Showing 38 changed files with 1,686 additions and 192 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"tomatophp/tomato-admin": "^1.1",
"tomatophp/console-helpers": "^1.1",
"tomatophp/tomato-model-generator": "^1.0",
"nwidart/laravel-modules": "^10.0",
"laravel/prompts": "^v0.1"
}
}
36 changes: 20 additions & 16 deletions src/Console/TomatoGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class TomatoGenerator extends Command
protected $signature = 'tomato:generate
{table=0}
{module=0}
{--api}
{--builder}
{--only-controllers}
';

/**
Expand Down Expand Up @@ -93,6 +93,8 @@ public function handle(): void
if (!$check) {
$createIt = confirm('Module not found! do you when to create it?');
$createIt ? $this->artisanCommand(["module:make", $moduleName]) : $moduleName = null;
\Laravel\Prompts\info('We Generate It please re-run the command again');
exit();
}
}
else {
Expand All @@ -109,28 +111,30 @@ public function handle(): void
}
}

$isBuilder = $this->option('builder') && $this->option('builder') != "0" ? $this->option('builder') : select(
label: 'Do you went to use Form Builder?',
options: ["form", "file"],
default: "file",
validate: fn (string $value) => match (true) {
strlen($value) === 'form' || strlen($value) === 'file' => 'Sorry please select form/file',
default => null
}
$generateAPI = ($this->option('api') && $this->option('api') != "0") ? $this->option('api') : confirm(
label: 'Do you went to generate api routes?',
);

$onlyController = $this->option('only-controllers') && $this->option('only-controllers') != "0" ? $this->option('only-controllers') : confirm(
label: 'Do you went to generate controllers Only?',
$generateForm = ($this->option('builder') && $this->option('builder') != "0") ? $this->option('builder') : confirm(
label: 'Do you went to use form class builder?',
);


//Generate CRUD Service
try {
$resourceGenerator = new CRUDGenerator(tableName:$tableName,moduleName:$moduleName,isBuilder: $isBuilder, isOnlyController: $onlyController);
$resourceGenerator->generate();
info('CRUD Has Been Generated Success');
\Laravel\Prompts\spin(fn()=> (new CRUDGenerator(
tableName:$tableName,
moduleName:$moduleName,
apiRoutes: $generateAPI,
form: $generateForm,
))->generate(), 'Generating ...');
} catch (\Exception $e) {
error($e);
\Laravel\Prompts\error($e);
}

\Laravel\Prompts\info('🍅 Thanks for using Tomato Plugins & TomatoPHP framework');
\Laravel\Prompts\info('💼 Join support server on discord https://discord.gg/VZc8nBJ3ZU');
\Laravel\Prompts\info('📄 You can check docs here https://docs.tomatophp.com');
\Laravel\Prompts\info('⭐ please gave us a start on any repo if you like it https://github.com/tomatophp');
\Laravel\Prompts\info('🤝 sponser us here https://github.com/sponsors/3x1io');
}
}
149 changes: 149 additions & 0 deletions src/Console/TomatoGeneratorControllers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<?php

namespace TomatoPHP\TomatoPHP\Console;

use Doctrine\DBAL\Schema\Schema;
use Illuminate\Console\Command;
use Illuminate\Support\Str;
use Nwidart\Modules\Facades\Module;
use TomatoPHP\ConsoleHelpers\Traits\RunCommand;
use TomatoPHP\TomatoPHP\Services\Generator\CRUDGenerator;
use function Laravel\Prompts\confirm;
use function Laravel\Prompts\search;
use function Laravel\Prompts\select;
use function Laravel\Prompts\text;
use function Laravel\Prompts\error;
use function Laravel\Prompts\warning;
use function Laravel\Prompts\suggest;

class TomatoGeneratorControllers extends Command
{
use RunCommand;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'tomato:controllers
{table=0}
{module=0}
{--request}
{--resource}
';

/**
* The console command description.
*
* @var string
*/
protected $description = 'generate controllers for the application by tomato';


/**
* @return void
*/
public function handle(): void
{

$tables = collect(\DB::select('SHOW TABLES'))->map(function ($item){
return $item->{'Tables_in_'.config('database.connections.mysql.database')};
})->toArray();

$tableName = $this->argument('table') && $this->argument('table') != "0" ? $this->argument('table') : search(
label: 'Please input your table name you went to create CRUD?',
options: fn (string $value) => strlen($value) > 0
? collect($tables)->filter(function ($item, $key) use ($value){
return Str::contains($item, $value) ? (string)$item : null;
})->toArray()
: [],
placeholder: "ex: users",
scroll: 10
);

if(is_numeric($tableName)){
$tableName = $tables[$tableName];
}
else {
$tableName = $tableName;
}

//Check if user need to use HMVC
$isModule = ($this->argument('module') && $this->argument('module') != "0") ?: confirm('Do you went to use HMVC module?');
$moduleName = false;
if ($isModule){
if (class_exists(\Nwidart\Modules\Facades\Module::class)){
$modules = \Nwidart\Modules\Facades\Module::toCollection()->map(function ($item){
return $item->getName();
});
$moduleName = ($this->argument('module') && $this->argument('module') != "0") ? $this->argument('module') : suggest(
label:'Please input your module name?',
placeholder:'Translations',
options: fn (string $value) => strlen($value) > 0
? collect($modules)->filter(function ($item, $key) use ($value){
return Str::contains($item, $value) ? $item : null;
})->toArray()
: [],
validate: fn (string $value) => match (true) {
strlen($value) < 1 => "Sorry this filed is required!",
default => null
},
scroll: 10
);
$check = \Nwidart\Modules\Facades\Module::find($moduleName);
if (!$check) {
$createIt = confirm('Module not found! do you when to create it?');
$createIt ? $this->artisanCommand(["module:make", $moduleName]) : $moduleName = null;
\Laravel\Prompts\info('We Generate It please re-run the command again');
exit();
}
}
else {
$installItem = confirm('Sorry nwidart/laravel-modules not installed please install it first. do you when to install it?');
if($installItem){
$this->requireComposerPackages(["nwidart/laravel-modules"]);
\Laravel\Prompts\info('Add This line to composer.json psr-4 autoload');
\Laravel\Prompts\info('"Modules\\" : "Modules/"');
\Laravel\Prompts\info('now run');
\Laravel\Prompts\info('composer dump-autoload');
\Laravel\Prompts\info('Install success please run the command again');
exit();
}
}
}

$generateRequest = ($this->option('request') && $this->option('request') != "0") ? $this->option('request') : confirm(
label: 'Do you went to generate form request?',
);

$generateResource = ($this->option('resource') && $this->option('resource') != "0") ? $this->option('resource') : confirm(
label: 'Do you went to generate json resource?',
);


//Generate CRUD Service
try {
\Laravel\Prompts\spin(fn()=> (new CRUDGenerator(
tableName:$tableName,
moduleName:$moduleName,
models: false,
views: false,
routes: false,
tables: false,
controllers: true,
request: $generateRequest,
json: $generateResource,
apiRoutes: false,
form: false,
menu: false,
))->generate(), 'Generating ...');
} catch (\Exception $e) {
\Laravel\Prompts\error($e);
}

\Laravel\Prompts\info('🍅 Thanks for using Tomato Plugins & TomatoPHP framework');
\Laravel\Prompts\info('💼 Join support server on discord https://discord.gg/VZc8nBJ3ZU');
\Laravel\Prompts\info('📄 You can check docs here https://docs.tomatophp.com');
\Laravel\Prompts\info('⭐ please gave us a start on any repo if you like it https://github.com/tomatophp');
\Laravel\Prompts\info('🤝 sponser us here https://github.com/sponsors/3x1io');
}
}
150 changes: 150 additions & 0 deletions src/Console/TomatoGeneratorForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?php

namespace TomatoPHP\TomatoPHP\Console;

use Doctrine\DBAL\Schema\Schema;
use Illuminate\Console\Command;
use Illuminate\Support\Str;
use Nwidart\Modules\Facades\Module;
use TomatoPHP\ConsoleHelpers\Traits\RunCommand;
use TomatoPHP\TomatoPHP\Services\Generator\CRUDGenerator;
use function Laravel\Prompts\confirm;
use function Laravel\Prompts\search;
use function Laravel\Prompts\select;
use function Laravel\Prompts\text;
use function Laravel\Prompts\error;
use function Laravel\Prompts\warning;
use function Laravel\Prompts\suggest;

class TomatoGeneratorForm extends Command
{
use RunCommand;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'tomato:form
{table=0}
{module=0}
{--views}
{--controller}
';

/**
* The console command description.
*
* @var string
*/
protected $description = 'create a new Form Class for the application by tomato';


/**
* @return void
*/
public function handle(): void
{

$tables = collect(\DB::select('SHOW TABLES'))->map(function ($item){
return $item->{'Tables_in_'.config('database.connections.mysql.database')};
})->toArray();

$tableName = $this->argument('table') && $this->argument('table') != "0" ? $this->argument('table') : search(
label: 'Please input your table name you went to create CRUD?',
options: fn (string $value) => strlen($value) > 0
? collect($tables)->filter(function ($item, $key) use ($value){
return Str::contains($item, $value) ? (string)$item : null;
})->toArray()
: [],
placeholder: "ex: users",
scroll: 10
);

if(is_numeric($tableName)){
$tableName = $tables[$tableName];
}
else {
$tableName = $tableName;
}

//Check if user need to use HMVC
$isModule = ($this->argument('module') && $this->argument('module') != "0") ?: confirm('Do you went to use HMVC module?');
$moduleName = false;
if ($isModule){
if (class_exists(\Nwidart\Modules\Facades\Module::class)){
$modules = \Nwidart\Modules\Facades\Module::toCollection()->map(function ($item){
return $item->getName();
});
$moduleName = ($this->argument('module') && $this->argument('module') != "0") ? $this->argument('module') : suggest(
label:'Please input your module name?',
placeholder:'Translations',
options: fn (string $value) => strlen($value) > 0
? collect($modules)->filter(function ($item, $key) use ($value){
return Str::contains($item, $value) ? $item : null;
})->toArray()
: [],
validate: fn (string $value) => match (true) {
strlen($value) < 1 => "Sorry this filed is required!",
default => null
},
scroll: 10
);
$check = \Nwidart\Modules\Facades\Module::find($moduleName);
if (!$check) {
$createIt = confirm('Module not found! do you when to create it?');
$createIt ? $this->artisanCommand(["module:make", $moduleName]) : $moduleName = null;
\Laravel\Prompts\info('We Generate It please re-run the command again');
exit();
}
}
else {
$installItem = confirm('Sorry nwidart/laravel-modules not installed please install it first. do you when to install it?');
if($installItem){
$this->requireComposerPackages(["nwidart/laravel-modules"]);
\Laravel\Prompts\info('Add This line to composer.json psr-4 autoload');
\Laravel\Prompts\info('"Modules\\" : "Modules/"');
\Laravel\Prompts\info('now run');
\Laravel\Prompts\info('composer dump-autoload');
\Laravel\Prompts\info('Install success please run the command again');
exit();
}
}
}

$generateControllers = ($this->option('controller') && $this->option('controller') != "0") ? $this->option('controller') : confirm(
label: 'Do you went to generate controllers for the form?',
);

$generateViews = ($this->option('views') && $this->option('views') != "0") ? $this->option('views') : confirm(
label: 'Do you went to generate views for the form?',
);



//Generate CRUD Service
try {
\Laravel\Prompts\spin(fn()=> (new CRUDGenerator(
tableName:$tableName,
moduleName:$moduleName,
models: false,
views: $generateViews,
routes: false,
tables: false,
controllers: $generateControllers,
request: false,
json: false,
apiRoutes: false,
form: true,
menu: false,
))->generate(), 'Generating ...');
} catch (\Exception $e) {
\Laravel\Prompts\error($e);
}

\Laravel\Prompts\info('🍅 Thanks for using Tomato Plugins & TomatoPHP framework');
\Laravel\Prompts\info('💼 Join support server on discord https://discord.gg/VZc8nBJ3ZU');
\Laravel\Prompts\info('📄 You can check docs here https://docs.tomatophp.com');
\Laravel\Prompts\info('⭐ please gave us a start on any repo if you like it https://github.com/tomatophp');
\Laravel\Prompts\info('🤝 sponser us here https://github.com/sponsors/3x1io');
}
}
Loading

0 comments on commit 5f7e59e

Please sign in to comment.