diff --git a/app/Console/Commands/Bundle/Render.php b/app/Console/Commands/Bundle/Render.php
index e88e9f8..9f58014 100644
--- a/app/Console/Commands/Bundle/Render.php
+++ b/app/Console/Commands/Bundle/Render.php
@@ -3,11 +3,11 @@
namespace App\Console\Commands\Bundle;
use App\Classes\Bundle;
+use App\Console\Commands\Bundle\Traits\ReadsBundles;
+use App\Console\Commands\Bundle\Traits\SelectsDisks;
use Illuminate\Console\Command;
-use Illuminate\Contracts\Filesystem\Filesystem;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Process;
-use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use function Laravel\Prompts\confirm;
@@ -15,6 +15,9 @@
class Render extends Command
{
+ use ReadsBundles;
+ use SelectsDisks;
+
/**
* The console command description.
*
@@ -22,10 +25,6 @@ class Render extends Command
*/
protected $description = 'Render bundles';
- protected Filesystem $sourceDisk;
-
- protected Filesystem $targetDisk;
-
public function __construct()
{
$this->signature = 'bundle:render
@@ -50,11 +49,12 @@ public function __construct()
public function handle()
{
$this->showDisclaimer()
- ->selectDisk()
+ ->selectDisk(true, true)
->renderAssets()
->clearCache()
->validate()
->renderFeed()
+ ->selectBundles()
->render()
->deploy();
}
@@ -75,28 +75,6 @@ private function showDisclaimer(): self
return $this;
}
- /**
- * Select the disk we will be working on
- */
- private function selectDisk(): self
- {
- $sourceDisk = $this->option('source-disk') ?? env('CONTENT_DISK');
- $targetDisk = $this->option('target-disk') ?? env('DIST_DISK');
-
- $this->sourceDisk = Storage::disk($sourceDisk);
- $this->targetDisk = Storage::disk($targetDisk);
-
- $this->line(
- sprintf(
- 'Using %s as source disk and %s as target disk for generated content',
- $sourceDisk,
- $targetDisk
- )
- );
-
- return $this;
- }
-
/**
* Build assets, and clear cache afterwise
*/
@@ -147,7 +125,13 @@ private function validate(): self
return $this;
}
- $result = $this->call('bundle:validate', ['--recursive' => true]);
+ $options = [
+ '--recursive' => $this->option('recursive'),
+ '--source-disk' => $this->option('source-disk'),
+ 'path' => $this->argument('path') ?? '/',
+ ];
+
+ $result = $this->call('bundle:validate', $options);
if (!empty($result)) {
if (confirm('Validation errors have occurred. Cancel process?')) {
@@ -158,32 +142,6 @@ private function validate(): self
return $this;
}
- /**
- * Collect a list of bundles to render
- */
- private function getBundles()
- {
- $path = $this->argument('path') ?? '/';
- $comment = sprintf('Rendering %s', $path);
-
- if ($this->option('recursive')) {
- $comment .= ' and all sub-bundles';
- }
-
- $this->line($comment);
- $this->output->write('Collecting bundles... ');
-
- if ($this->option('recursive')) {
- $bundles = Bundle::findBundles($this->sourceDisk, $path, true, false);
- } else {
- $bundles = [new Bundle($path, $this->sourceDisk)];
- }
-
- $this->info('OK');
-
- return $bundles;
- }
-
private function renderFeed(): self
{
$result = Bundle::renderFeed($this->sourceDisk);
@@ -218,7 +176,7 @@ private function renderFeed(): self
*/
private function render(): self
{
- $bundles = $this->getBundles();
+ $bundles = $this->bundles;
progress(
label: 'Rendering... ',
diff --git a/app/Console/Commands/Bundle/Repair.php b/app/Console/Commands/Bundle/Repair.php
index 4e9b4f0..2e34560 100644
--- a/app/Console/Commands/Bundle/Repair.php
+++ b/app/Console/Commands/Bundle/Repair.php
@@ -3,56 +3,56 @@
namespace App\Console\Commands\Bundle;
use App\Classes\Bundle;
+use App\Console\Commands\Bundle\Traits\ReadsBundles;
+use App\Console\Commands\Bundle\Traits\SelectsDisks;
use Carbon\Carbon;
use Illuminate\Console\Command;
-use Illuminate\Support\Facades\Storage;
+
+use function Laravel\Prompts\progress;
class Repair extends Command
{
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'bundle:repair { --r|recursive : Also repair sub-bundles } { path? : Specific bundle to repair }';
+ use ReadsBundles;
+ use SelectsDisks;
/**
* The console command description.
*
* @var string
*/
- protected $description = 'Repair articles';
+ protected $description = 'Repair bundles';
+
+ public function __construct()
+ {
+ $this->signature = 'bundle:repair
+ { --r|recursive : Also repair sub-bundles }
+ { --source-disk= : Use specified content disk - Defaults to ' . env('CONTENT_DISK') . ' }
+ { path? : Path to a specific bundle to repair - Default to / }
+ ';
+
+ parent::__construct();
+ }
/**
* Execute the console command.
*/
public function handle()
{
- $disk = Storage::disk(env('CONTENT_DISK'));
- $path = $this->argument('path') ?? '/';
-
- if ($this->option('recursive')) {
- $bundles = Bundle::findBundles($disk, $path, true);
- } else {
- $bundles = [new Bundle($path, $disk)];
- }
-
- foreach ($bundles as $bundle) {
- $this->output->write(sprintf('Repairing %s... ', $bundle->getPath()));
-
- $bundle->repair();
-
- $this->info('OK');
- }
+ $this->selectDisk()
+ ->selectBundles()
+ ->repair();
foreach (['blog', 'liens-interessants'] as $section) {
$this->createIntermediateBundles($section);
}
}
- protected function createIntermediateBundles($parent)
+ /**
+ * Create intermediary bundles
+ */
+ private function createIntermediateBundles($parent)
{
- $disk = Storage::disk(env('CONTENT_DISK'));
+ $disk = $this->sourceDisk;
foreach ($disk->directories($parent) as $dir) {
if (basename($dir) === 'data') {
@@ -93,11 +93,29 @@ protected function createIntermediateBundles($parent)
}
$bundle->save();
-
- $this->line(sprintf('Created intermediary bundle %s', $bundle->getPath()));
}
$this->createIntermediateBundles($bundle->getPath());
}
}
+
+ /**
+ * Repair bundles
+ */
+ private function repair()
+ {
+ progress('Repairing bundles...', $this->bundles, function (Bundle $bundle, $progress) {
+ $this->handleBundle($bundle, $progress);
+ });
+ }
+
+ /**
+ * Repair specific bundle
+ */
+ private function handleBundle(Bundle $bundle, $progress)
+ {
+ $bundle->repair();
+
+ $progress->label(sprintf('Repaired %s', $bundle->getPath()));
+ }
}
diff --git a/app/Console/Commands/Bundle/Touch.php b/app/Console/Commands/Bundle/Touch.php
deleted file mode 100644
index 754e3c1..0000000
--- a/app/Console/Commands/Bundle/Touch.php
+++ /dev/null
@@ -1,34 +0,0 @@
-argument('path'), Storage::disk(env('CONTENT_DISK')));
-
- $bundle->touch();
- }
-}
diff --git a/app/Console/Commands/Bundle/Traits/ReadsBundles.php b/app/Console/Commands/Bundle/Traits/ReadsBundles.php
index d14a700..620015c 100644
--- a/app/Console/Commands/Bundle/Traits/ReadsBundles.php
+++ b/app/Console/Commands/Bundle/Traits/ReadsBundles.php
@@ -14,7 +14,7 @@ trait ReadsBundles
protected function selectBundles(): self
{
$path = $this->argument('path') ?? '/';
- $comment = sprintf('Validating %s', $path);
+ $comment = sprintf('Reading %s', $path);
if ($this->option('recursive')) {
$comment .= ' and all sub-bundles';
diff --git a/app/Console/Commands/Bundle/Traits/SelectsDisks.php b/app/Console/Commands/Bundle/Traits/SelectsDisks.php
index 7bc0fc1..080e6af 100644
--- a/app/Console/Commands/Bundle/Traits/SelectsDisks.php
+++ b/app/Console/Commands/Bundle/Traits/SelectsDisks.php
@@ -9,10 +9,25 @@ trait SelectsDisks
{
protected Filesystem $sourceDisk;
+ protected Filesystem $targetDisk;
+
/**
* Select the disk we will be working on
*/
- private function selectDisk(): self
+ private function selectDisk(?bool $source = true, ?bool $target = false): self
+ {
+ if ($source) {
+ $this->selectSourceDisk();
+ }
+
+ if ($target) {
+ $this->selectTargetDisk();
+ }
+
+ return $this;
+ }
+
+ private function selectSourceDisk()
{
$sourceDisk = $this->option('source-disk') ?? env('CONTENT_DISK');
@@ -27,4 +42,20 @@ private function selectDisk(): self
return $this;
}
+
+ private function selectTargetDisk()
+ {
+ $targetDisk = $this->option('target-disk') ?? env('DIST_DISK');
+
+ $this->targetDisk = Storage::disk($targetDisk);
+
+ $this->line(
+ sprintf(
+ 'Using %s as target disk',
+ $targetDisk
+ )
+ );
+
+ return $this;
+ }
}
diff --git a/app/Console/Commands/Bundle/Update.php b/app/Console/Commands/Bundle/Update.php
index be78959..a4b552a 100644
--- a/app/Console/Commands/Bundle/Update.php
+++ b/app/Console/Commands/Bundle/Update.php
@@ -33,9 +33,9 @@ class Update extends Command
public function __construct()
{
$this->signature = 'bundle:update
- { --r|recursive : Also validate sub-bundles }
+ { --r|recursive : Also update sub-bundles }
{ --source-disk= : Use specified content disk - Defaults to ' . env('CONTENT_DISK') . ' }
- { path? : Path to a specific bundle to validate - Default to / }
+ { path? : Path to a specific bundle to update - Default to / }
';
parent::__construct();
@@ -55,7 +55,7 @@ public function handle()
/**
* Updates specific bundle
*/
- protected function handleBundle(Bundle $bundle, $progress)
+ private function handleBundle(Bundle $bundle, $progress)
{
$progress->hint(sprintf('Updated %s', $bundle->getPath()));
diff --git a/app/Console/Commands/Bundle/Upgrade.php b/app/Console/Commands/Bundle/Upgrade.php
index 2000713..4c541c7 100644
--- a/app/Console/Commands/Bundle/Upgrade.php
+++ b/app/Console/Commands/Bundle/Upgrade.php
@@ -3,17 +3,16 @@
namespace App\Console\Commands\Bundle;
use App\Classes\Bundle;
+use App\Console\Commands\Bundle\Traits\ReadsBundles;
+use App\Console\Commands\Bundle\Traits\SelectsDisks;
use Illuminate\Console\Command;
-use Illuminate\Support\Facades\Storage;
+
+use function Laravel\Prompts\progress;
class Upgrade extends Command
{
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'bundle:upgrade { path? : Specific bundle to upgrade }';
+ use ReadsBundles;
+ use SelectsDisks;
/**
* The console command description.
@@ -22,30 +21,36 @@ class Upgrade extends Command
*/
protected $description = 'Upgrade bundles from previous CMS version';
+ public function __construct()
+ {
+ $this->signature = 'bundle:upgrade
+ { --r|recursive : Also upgrade sub-bundles }
+ { --source-disk= : Use specified content disk - Defaults to ' . env('CONTENT_DISK') . ' }
+ { path? : Path to a specific bundle to upgrade - Default to / }
+ ';
+
+ parent::__construct();
+ }
+
/**
* Execute the console command.
*/
public function handle()
{
- $disk = Storage::disk(env('CONTENT_DISK'));
- $path = $this->argument('path') ?? '/';
- $bundles = Bundle::findBundles($disk, $path, true);
+ $this->selectDisk()
+ ->selectBundles()
+ ->upgrade();
+ }
- foreach ($bundles as $bundle) {
- $this->output->write(sprintf('Upgrading %s... ', $bundle->getPath()));
+ private function upgrade()
+ {
+ progress('Upgrading bundles...', $this->bundles, function (Bundle $bundle, $progress) {
+ $this->handleBundle($bundle, $progress);
+ });
+ }
- $bundle->metadata()->remove('lastModified');
- $bundle->metadata()->remove('lastRendered');
-
- $bundle->metadata('links')->clear();
- $bundle->metadata('links')->save();
-
- $bundle->metadata('rebrickable')->clear();
- $bundle->metadata('rebrickable')->save();
-
- $bundle->save();
-
- $this->info('OK');
- }
+ private function handleBundle(Bundle $bundle, $progress)
+ {
+ //
}
}
diff --git a/app/Console/Commands/Bundle/Validate.php b/app/Console/Commands/Bundle/Validate.php
index a66fef8..09fb955 100644
--- a/app/Console/Commands/Bundle/Validate.php
+++ b/app/Console/Commands/Bundle/Validate.php
@@ -3,11 +3,11 @@
namespace App\Console\Commands\Bundle;
use App\Classes\Bundle;
+use App\Console\Commands\Bundle\Traits\ReadsBundles;
+use App\Console\Commands\Bundle\Traits\SelectsDisks;
use App\Services\HtmlValidator;
use Illuminate\Console\Command;
-use Illuminate\Contracts\Filesystem\Filesystem;
use Illuminate\Support\Facades\Cache;
-use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Vite;
use Illuminate\Support\Str;
use JsonSchema\Validator;
@@ -16,6 +16,9 @@
class Validate extends Command
{
+ use ReadsBundles;
+ use SelectsDisks;
+
/**
* The console command description.
*
@@ -23,16 +26,12 @@ class Validate extends Command
*/
protected $description = 'Validate bundles metadata';
- protected Filesystem $sourceDisk;
-
protected array $invalidJson = [];
protected array $invalidHtml = [];
protected array $invalidCss = [];
- protected $bundles;
-
public function __construct()
{
$this->signature = 'bundle:validate
@@ -68,53 +67,6 @@ public function handle()
}
}
- /**
- * Select the disk we will be working on
- */
- private function selectDisk(): self
- {
- $sourceDisk = $this->option('source-disk') ?? env('CONTENT_DISK');
-
- $this->sourceDisk = Storage::disk($sourceDisk);
-
- $this->line(
- sprintf(
- 'Using %s as source disk',
- $sourceDisk
- )
- );
-
- return $this;
- }
-
- /**
- * Collect a list of bundles to validate
- */
- private function selectBundles(): self
- {
- $path = $this->argument('path') ?? '/';
- $comment = sprintf('Validating %s', $path);
-
- if ($this->option('recursive')) {
- $comment .= ' and all sub-bundles';
- }
-
- $this->line($comment);
- $this->output->write('Collecting bundles... ');
-
- if ($this->option('recursive')) {
- $bundles = Bundle::findBundles($this->sourceDisk, $path, true);
- } else {
- $bundles = [new Bundle($path, $this->sourceDisk)];
- }
-
- $this->bundles = $bundles;
-
- $this->info('OK');
-
- return $this;
- }
-
/**
* Return an associative array containing available bundles metadata files
* as keys and json-decoded validation schemas as values
@@ -154,11 +106,7 @@ private function validateJson(): self
*/
private function handleBundleJsonValidation(Bundle $bundle, $progress, $validators)
{
- $progress->label(sprintf('Validating %s ...', $bundle->getPath()));
-
foreach ($validators as $metadataFilename => $schema) {
- $progress->hint(sprintf('Validating %s ...', $metadataFilename));
-
$filepath = $bundle->metadata($metadataFilename)->getFilename();
if (!$this->sourceDisk->exists($filepath)) {
@@ -178,6 +126,8 @@ private function handleBundleJsonValidation(Bundle $bundle, $progress, $validato
];
}
}
+
+ $progress->label(sprintf('Validated %s', $bundle->getPath()));
}
private function validateCss(): self
@@ -234,8 +184,6 @@ private function validateHtml(): self
private function handleBundleHtmlValidation(Bundle $bundle, $progress)
{
- $progress->label(sprintf('Validating %s ...', $bundle->getPath()));
-
$rendered = $bundle->render();
$changed = false;
@@ -259,6 +207,8 @@ private function handleBundleHtmlValidation(Bundle $bundle, $progress)
if ($changed) {
$bundle->touch();
}
+
+ $progress->label(sprintf('Validated %s', $bundle->getPath()));
}
/**