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;
|
|
|
|
|
2024-05-03 16:16:19 +02:00
|
|
|
use function Laravel\Prompts\confirm;
|
2024-04-27 22:21:12 +02:00
|
|
|
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-29 11:36:03 +02:00
|
|
|
if ($this->option('assets')) {
|
2024-04-28 11:34:20 +02:00
|
|
|
$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();
|
|
|
|
|
2024-05-03 16:16:19 +02:00
|
|
|
if (confirm('Ready to deploy?')) {
|
|
|
|
$this->output->write('Deploying... ');
|
|
|
|
$source = Str::finish(Storage::disk(env('DIST_DISK'))->path('/'), '/');
|
|
|
|
$target = env('DEPLOY_TARGET');
|
2024-04-27 22:21:12 +02:00
|
|
|
|
2024-05-03 16:16:19 +02:00
|
|
|
$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);
|
2024-04-27 22:21:12 +02:00
|
|
|
|
2024-05-03 16:16:19 +02:00
|
|
|
Process::run($command)->throw();
|
|
|
|
$this->info('OK');
|
|
|
|
}
|
2024-04-27 22:21:12 +02:00
|
|
|
}
|
|
|
|
}
|