Skip to content

Commit

Permalink
Display error when the blocks dir is not found (#421)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonioribeiro authored and ifox committed Oct 17, 2019
1 parent 702e31a commit fed7b92
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/Commands/GenerateBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

class GenerateBlocks extends Command
{
const NO_BLOCKS_DEFINED = "There are no blocks defined yet. Please refer to https://twill.io/docs/#block-editor-3 in order to create blocks.";
const SCANNING_BLOCKS = "Starting to scan block views directory...";

/**
* The name and signature of the console command.
*
Expand Down Expand Up @@ -53,8 +56,15 @@ public function __construct(Filesystem $filesystem, ViewFactory $viewFactory)
*/
public function handle()
{
$this->info("Starting to scan block views directory...");
Collection::make($this->filesystem->files(resource_path('views/admin/blocks')))->each(function ($viewFile) {
if (!$this->filesystem->exists($path = resource_path('views/admin/blocks'))) {
$this->error(self::NO_BLOCKS_DEFINED);

return;
}

$this->info(self::SCANNING_BLOCKS);

Collection::make($this->filesystem->files($path))->each(function ($viewFile) {
$blockName = $viewFile->getBasename('.blade.php');

$vueBlockTemplate = $this->viewFactory->make('admin.blocks.' . $blockName, ['renderForBlocks' => true])->render();
Expand Down Expand Up @@ -111,5 +121,4 @@ private function sanitize($html)

return preg_replace($search, $replace, $html);
}

}

0 comments on commit fed7b92

Please sign in to comment.