Deploying
This commit is contained in:
parent
1c2af2be71
commit
5b173ac989
68
app/Console/Commands/Bundle/Render.php
Normal file
68
app/Console/Commands/Bundle/Render.php
Normal 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');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user