From 5b173ac989a0256897249e7681055ebe0933179a Mon Sep 17 00:00:00 2001 From: Richard Dern Date: Sat, 27 Apr 2024 22:21:12 +0200 Subject: [PATCH] Deploying --- app/Console/Commands/Bundle/Render.php | 68 ++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 app/Console/Commands/Bundle/Render.php diff --git a/app/Console/Commands/Bundle/Render.php b/app/Console/Commands/Bundle/Render.php new file mode 100644 index 0000000..0f9215a --- /dev/null +++ b/app/Console/Commands/Bundle/Render.php @@ -0,0 +1,68 @@ +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'); + } +}