1
0
cms11/app/Console/Commands/Bundle/Render.php

73 lines
1.9 KiB
PHP
Raw Normal View History

2024-04-27 22:21:12 +02:00
<?php
namespace App\Console\Commands\Bundle;
use App\Classes\Bundle;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Process;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use function Laravel\Prompts\progress;
class Render extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
2024-04-28 11:34:20 +02:00
protected $signature = 'bundle:render { --a|assets : Rebuild assets }';
2024-04-27 22:21:12 +02:00
/**
* The console command description.
*
* @var string
*/
protected $description = 'Render bundles';
/**
* Execute the console command.
*/
public function handle()
{
2024-04-28 11:34:20 +02:00
if ($this->options('assets')) {
$this->output->write('Building assets... ');
Process::run('npm run build')->throw();
$this->info('OK');
$this->call('cache:clear');
}
2024-04-27 22:21:12 +02:00
$path = '/';
$bundles = Bundle::findBundles(Storage::disk(env('CONTENT_DISK')), $path, true);
$progress = progress(label: 'Rendering... ', steps: count($bundles));
$progress->start();
foreach ($bundles as $bundle) {
2024-04-28 11:34:20 +02:00
$result = $bundle->render();
2024-04-27 22:21:12 +02:00
foreach ($result as $path => $content) {
if (!Str::contains($path, '.')) {
$path = Str::finish($path, '/') . 'index.html';
}
Storage::disk(env('DIST_DISK'))->put($path, $content);
}
$progress->advance();
}
$progress->finish();
$this->output->write('Deploying... ');
$source = Str::finish(Storage::disk(env('DIST_DISK'))->path('/'), '/');
$target = env('DEPLOY_TARGET');
$command = sprintf('rsync -az -L --chmod=Du=rwx,Dg=rx,Do=rx,Fu=rw,Fg=r,Fo=r --chown=caddy:caddy --delete "%s" "%s"', $source, $target);
Process::run($command)->throw();
$this->info('OK');
}
}