added theme part command

pull/44/head
A1Gard 3 months ago
parent 801de6ae1d
commit ecd926b9ed

@ -0,0 +1,16 @@
<?php
namespace App\Http\Controllers;
class Handle
{
public static function onAdd(){
}
public static function onRemove(){
}
public static function onMount(){
}
}

@ -0,0 +1,91 @@
<?php
namespace App\Console\Commands;
use App\Models\Theme;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
class makePart extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'make:part {part} {section}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'make theme part';
/**
* Execute the console command.
*/
public function handle()
{
//
$part = strtolower($this->argument('part'));
$section = strtolower($this->argument('section'));
// make detail
$detail = [
'name' => $part,
'version' => '1.0',
'author' => 'xStack',
'email' => 'xshop@xstack.ir',
'license' => 'GPL-3.0-or-later',
'url' => 'https://xstack.ir',
'author_url' => 'https://4xmen.ir',
'packages' => [],
];
// check section
if (!in_array($section, Theme::$sections)) {
$this->error(__('Invalid theme section'));
return -1;
}
$folderPath = __DIR__ . '/../../../resources/views/theme/' . $section . '/' . $part;
// check is exists
if (File::exists($folderPath)) {
$this->warn(__('Command ignored, theme part exists!'));
return -1;
}
// create folder
File::makeDirectory($folderPath, 0755, true);
File::makeDirectory($folderPath.'/assets', 0755, true);
$this->info('Directory created as: /theme/' . $section . '/' . $part);
$handler = file_get_contents(__DIR__.'/data/handle.dat');
$handler = str_replace('Handle',ucfirst($part), $handler);
$scss = <<<DOC
#$part {
// scss
}
DOC;
file_put_contents($folderPath . '/' . $part . '.blade.php', "<div id='{$part}'></div>");
file_put_contents($folderPath . '/' . $part . '.js', '');
file_put_contents($folderPath . '/' . $part . '.json', json_encode($detail,JSON_PRETTY_PRINT));
file_put_contents($folderPath . '/' . ucfirst($part) . '.php', $handler);
file_put_contents($folderPath . '/' . $part . '.scss', $scss);
File::copy(__DIR__.'/data/screenshot.dat',$folderPath .'/screenshot.png');
$this->info(__("Theme part created successfully: [blade, js, json, scss, php, assets, screenshot]"));
return 0;
}
}

@ -21,7 +21,7 @@ class makeXcontroller extends Command
* *
* @var string * @var string
*/ */
protected $description = 'create new xContoller'; protected $description = 'create new xController';
/** /**
* Execute the console command. * Execute the console command.
@ -41,7 +41,7 @@ class makeXcontroller extends Command
} }
// get controller content // get controller content
$content = file_get_contents(__DIR__ . '/xcontroller.dat'); $content = file_get_contents(__DIR__ . '/data/xcontroller.dat');
// replace variables // replace variables
$content = str_replace('User', $model, $content); $content = str_replace('User', $model, $content);
@ -77,13 +77,13 @@ class makeXcontroller extends Command
// make list blade // make list blade
$model = strtolower($model); $model = strtolower($model);
$content = file_get_contents(__DIR__ . '/listblade.dat'); $content = file_get_contents(__DIR__ . '/data/listblade.dat');
$content = str_replace('Users',$plural,$content); $content = str_replace('Users',$plural,$content);
file_put_contents($folderPath.'/'.$model.'-list.blade.php',$content); file_put_contents($folderPath.'/'.$model.'-list.blade.php',$content);
$this->info($model.'-list.blade.php created'); $this->info($model.'-list.blade.php created');
// make form blade // make form blade
$content = file_get_contents(__DIR__ . '/formblade.dat'); $content = file_get_contents(__DIR__ . '/data/formblade.dat');
$content = str_replace('Users',$plural,$content); $content = str_replace('Users',$plural,$content);
$content = str_replace('user',strtolower($model),$content); $content = str_replace('user',strtolower($model),$content);
file_put_contents($folderPath.'/'.$model.'-form.blade.php',$content); file_put_contents($folderPath.'/'.$model.'-form.blade.php',$content);

@ -1,6 +1,7 @@
{ {
"private": true, "private": true,
"type": "module", "type": "module",
"license": "GPL-3.0-or-later",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "vite build" "build": "vite build"

@ -104,5 +104,4 @@
value="{{old($setting->key, $setting->value)}}" @if($setting->ltr) dir="ltr" @endif> value="{{old($setting->key, $setting->value)}}" @if($setting->ltr) dir="ltr" @endif>
@endif @endif
@endswitch @endswitch
</div> </div>

Loading…
Cancel
Save