1
0

Deploying

This commit is contained in:
Richard Dern 2024-04-27 22:21:12 +02:00
parent 1c2af2be71
commit 5b173ac989

View File

@ -0,0 +1,68 @@
<?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
*/
protected $signature = 'bundle:render { --i|ignore-cache : Ignore cache }';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Render bundles';
/**
* Execute the console command.
*/
public function handle()
{
$this->output->write('Building assets... ');
Process::run('npm run build')->throw();
$this->info('OK');
$path = '/';
$bundles = Bundle::findBundles(Storage::disk(env('CONTENT_DISK')), $path, true);
$progress = progress(label: 'Rendering... ', steps: count($bundles));
$progress->start();
foreach ($bundles as $bundle) {
$result = $bundle->render($this->option('ignore-cache'));
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');
}
}