added assets build command to use by site

master
A1Gard 4 weeks ago
parent a117e04ee4
commit d1ee8fe206

@ -150,6 +150,7 @@ php artisan make:part PartName segmentName
```bash ```bash
php artisan client php artisan client
php artisan build
``` ```
</div> </div>

@ -122,6 +122,7 @@ Optimize client assets, `scss`,`js`,`css`
```bash ```bash
php artisan client php artisan client
php artisan build
``` ```
### theme parts file ### theme parts file

@ -0,0 +1,130 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
class AssetsBuild extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'build';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Safely run npm build process ';
/**
* Store command output
*/
private $commandOutput = '';
/**
* Get Laravel root path
*/
private function getLaravelRoot()
{
return base_path();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
try {
// Set working directory to Laravel root
chdir($this->getLaravelRoot());
// Check if npm is installed
$npmVersion = new Process(['npm', '-v']);
$npmVersion->setWorkingDirectory($this->getLaravelRoot());
$npmVersion->run();
if (!$npmVersion->isSuccessful()) {
$this->addOutput('npm is not installed. Please install npm first.');
return Command::FAILURE;
}
// Check if package.json exists
if (!file_exists($this->getLaravelRoot() . '/package.json')) {
$this->addOutput('package.json not found in ' . $this->getLaravelRoot());
return Command::FAILURE;
}
// Check if node_modules exists
if (!file_exists($this->getLaravelRoot() . '/node_modules')) {
$this->addOutput('node_modules not found. Installing dependencies...');
$installProcess = new Process(['npm', 'install']);
$installProcess->setWorkingDirectory($this->getLaravelRoot());
$installProcess->setTimeout(3600); // 1 hour timeout
$installProcess->run(function ($type, $buffer) {
$this->addOutput($buffer);
});
if (!$installProcess->isSuccessful()) {
throw new ProcessFailedException($installProcess);
}
}
// Run npm build
$this->addOutput('Starting build process in: ' . $this->getLaravelRoot());
$buildProcess = new Process(['./node_modules/.bin/vite', 'build']);
$buildProcess->setWorkingDirectory($this->getLaravelRoot());
// $this->addOutput($this->getLaravelRoot());
$buildProcess->setTimeout(3600); // 1 hour timeout
$buildProcess->run(function ($type, $buffer) {
$this->addOutput($buffer);
});
if (!$buildProcess->isSuccessful()) {
throw new ProcessFailedException($buildProcess);
}
$this->addOutput('Build completed successfully!');
// Store output in cache for retrieval
cache()->put('build_command_output', $this->commandOutput, now()->addMinutes(5));
return Command::SUCCESS;
} catch (\Exception $e) {
$errorMessage = 'Build process failed: ' . $e->getMessage();
$this->addOutput($errorMessage);
cache()->put('build_command_output', $this->commandOutput, now()->addMinutes(5));
return Command::FAILURE;
}
}
/**
* Add output to both console and stored output
*/
private function addOutput($output)
{
$this->commandOutput .= $output . PHP_EOL;
$this->info($output); // This will only show in CLI
}
/**
* Get the command output
*/
public function getOutput()
{
return $this->commandOutput;
}
}

@ -222,4 +222,26 @@ class AreaController extends Controller
logAdmin(__METHOD__, __CLASS__, $p->area_id); logAdmin(__METHOD__, __CLASS__, $p->area_id);
return ['OK' => true, 'message' => __("As you wished sort saved")]; return ['OK' => true, 'message' => __("As you wished sort saved")];
} }
public function build(){
$exitCode = \Artisan::call('build');
// Get the command output from cache
$output = cache()->get('build_command_output', 'No output available');
// return response()->json([
// 'success' => $exitCode === 0,
// 'exit_code' => $exitCode,
// 'output' => $output
// ]);
logAdmin(__METHOD__, __CLASS__, null);
if ($exitCode == 0){
\Log::info($output);
return redirect()->back()->with(['message' => __('Assets build successfully')]);
}else{
\Log::error($output);
return redirect()->back()->with(['message' => __('Assets build failed')]);
}
}
} }

@ -1,11 +1,11 @@
<?php <?php
namespace App\Providers; namespace App\Providers;
use App\Console\Commands\AssetsBuild;
use App\Helpers\TDate; use App\Helpers\TDate;
use App\Http\Middleware\Acl; use App\Http\Middleware\Acl;
use App\Models\Area; use App\Models\Area;
use App\Models\Part; use App\Models\Part;
use App\Observers\AreaObsever;
use App\Observers\PartObsever; use App\Observers\PartObsever;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Pagination\Paginator; use Illuminate\Pagination\Paginator;
@ -23,6 +23,7 @@ class AppServiceProvider extends ServiceProvider
// //
$this->commands([ $this->commands([
TranslatorCommand::class, TranslatorCommand::class,
AssetsBuild::class,
]); ]);
foreach (config('xshop.payment.gateways') as $gateway){ foreach (config('xshop.payment.gateways') as $gateway){
/** @var \App\Contracts\Payment $gateway */ /** @var \App\Contracts\Payment $gateway */

@ -11,7 +11,7 @@ const responsiveControl = function () {
document.querySelectorAll('.table-list')?.forEach(function (table) { document.querySelectorAll('.table-list')?.forEach(function (table) {
console.log(table); // console.log(table);
// Get all the header cells // Get all the header cells
const headers = Array.from(table.querySelectorAll('th')).map(th => th.textContent.trim()); const headers = Array.from(table.querySelectorAll('th')).map(th => th.textContent.trim());

@ -87,6 +87,8 @@
"As you wished restored successfully": "همانطور که شما مایل بودید بازیافت شد", "As you wished restored successfully": "همانطور که شما مایل بودید بازیافت شد",
"As you wished sort saved": "همانطور که شما مایل بودید مرتب شدند", "As you wished sort saved": "همانطور که شما مایل بودید مرتب شدند",
"As you wished updated successfully": "همانطور که شما مایل بودید به روز شد", "As you wished updated successfully": "همانطور که شما مایل بودید به روز شد",
"Assets build failed": "دارایی‌ها ساخته نشده‌اند",
"Assets build successfully": "دارایی‌ها با موفقیت ساخته شدن",
"Attaching": "پیوست کردن", "Attaching": "پیوست کردن",
"Attachment": "پیوست", "Attachment": "پیوست",
"Attachments": "پیوست‌ها", "Attachments": "پیوست‌ها",
@ -105,6 +107,7 @@
"Batch delete": "حذف چندگانه", "Batch delete": "حذف چندگانه",
"Batch restore": "بازیافت چندگانه", "Batch restore": "بازیافت چندگانه",
"Before proceeding, please check your email for a verification link.": "قبل از ادامه فرآیند لطفا رایانه خودتون رو بررسی کنید که لینک ارسال شده باشد", "Before proceeding, please check your email for a verification link.": "قبل از ادامه فرآیند لطفا رایانه خودتون رو بررسی کنید که لینک ارسال شده باشد",
"Build assets": "ساخت دارایی‌های طراحی",
"Bulk actions:": "کار دسته‌جمعی", "Bulk actions:": "کار دسته‌جمعی",
"Cache cleared": "حافظه نهان پاک شد", "Cache cleared": "حافظه نهان پاک شد",
"Call us!": "با ما تماس بگیرید!", "Call us!": "با ما تماس بگیرید!",
@ -423,6 +426,7 @@
"SEO Score": "امتیاز سئو", "SEO Score": "امتیاز سئو",
"SKU": "", "SKU": "",
"SMS": "پیامک", "SMS": "پیامک",
"SVG image": "تصویر SVG",
"Save": "ذخیره", "Save": "ذخیره",
"Save all settings": "ذخیره همه تنظیمات", "Save all settings": "ذخیره همه تنظیمات",
"Search": "جستجو", "Search": "جستجو",
@ -463,7 +467,8 @@
"Sliders": "اسلایدرها", "Sliders": "اسلایدرها",
"Sliders list": "فهرست اسلایدر", "Sliders list": "فهرست اسلایدر",
"Slug": "نامک", "Slug": "نامک",
"Sort": "مرتب", "Sort": "ترتیب",
"Sort & filter": "ترتیب و صافی",
"State": "استان", "State": "استان",
"States": "استان‌ها", "States": "استان‌ها",
"States list": "فهرست استان‌ها", "States list": "فهرست استان‌ها",
@ -476,6 +481,7 @@
"Subtitle": "زیرعنوان", "Subtitle": "زیرعنوان",
"Successfully Invoices": "صورت‌حساب های موفق", "Successfully Invoices": "صورت‌حساب های موفق",
"Summary": "خلاصه", "Summary": "خلاصه",
"Svg image": "تصویر SVG",
"System notification": "پیام سیستم", "System notification": "پیام سیستم",
"Table of contents": "فهرست عناوین", "Table of contents": "فهرست عناوین",
"Tag": "برچسب", "Tag": "برچسب",
@ -619,6 +625,7 @@
"news": "خبر", "news": "خبر",
"not searchable": "غیرقابل جستجو", "not searchable": "غیرقابل جستجو",
"one second ago": "یک ثانیه پیش", "one second ago": "یک ثانیه پیش",
"or build it using the button below": "یا توسط دکمه ساختن دارایی پایین اقدام کنید",
"paragraphs": "بند", "paragraphs": "بند",
"parent_id": "والد", "parent_id": "والد",
"password repeat": "تکرار گذرواژه", "password repeat": "تکرار گذرواژه",

@ -7,8 +7,10 @@
@if(config('app.demo')) @if(config('app.demo'))
<div class="alert alert-warning"> <div class="alert alert-warning">
{{__("Theme loaded every :M minutes in demo version", ['M' => 5])}} {{__("Theme loaded every :M minutes in demo version", ['M' => 5])}}
{{__("or build it using the button below")}}
</div> </div>
@endif @endif
@include('components.err')
<div class="row"> <div class="row">
@foreach($areas as $area) @foreach($areas as $area)
<div class="col-md-4"> <div class="col-md-4">
@ -18,5 +20,11 @@
</a> </a>
</div> </div>
@endforeach @endforeach
<div class="col-md-4">
<a class="area-list-item " style="background: blueviolet" href="{{route('admin.area.build')}}">
<i class="ri-hammer-line"></i>
{{__("Build assets")}}
</a>
</div>
</div> </div>
@endsection @endsection

@ -361,6 +361,7 @@ Route::prefix(config('app.panel.prefix'))->name('admin.')->group(
Route::post('update/{area}', [\App\Http\Controllers\Admin\AreaController::class, "update"])->name('update'); Route::post('update/{area}', [\App\Http\Controllers\Admin\AreaController::class, "update"])->name('update');
Route::post('update/model/{model}/{id}', [\App\Http\Controllers\Admin\AreaController::class, "updateModel"])->name('update.model'); Route::post('update/model/{model}/{id}', [\App\Http\Controllers\Admin\AreaController::class, "updateModel"])->name('update.model');
Route::get('sort/{area}', [\App\Http\Controllers\Admin\AreaController::class, "sort"])->name('sort'); Route::get('sort/{area}', [\App\Http\Controllers\Admin\AreaController::class, "sort"])->name('sort');
Route::get('build', [\App\Http\Controllers\Admin\AreaController::class, "build"])->name('build');
Route::post('sort-save/{area}', [\App\Http\Controllers\Admin\AreaController::class, "sortSave"])->name('sort-save'); Route::post('sort-save/{area}', [\App\Http\Controllers\Admin\AreaController::class, "sortSave"])->name('sort-save');
} }
); );

Loading…
Cancel
Save