Skip to content

Commit

Permalink
Ensure ensured fields are added to definition
Browse files Browse the repository at this point in the history
  • Loading branch information
aerni committed Aug 28, 2024
1 parent 374ee32 commit d35b878
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions src/Console/Commands/MakeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@

namespace Aerni\Factory\Console\Commands;

use Aerni\Factory\Console\Commands\Concerns\GetsRelativePath;
use Aerni\Factory\Console\Commands\Concerns\SavesFile;
use Aerni\Factory\Factories\DefinitionGenerator;
use Aerni\Factory\Factories\Factory;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
use Statamic\Console\RunsInPlease;
use Statamic\Facades\Collection;
use Statamic\Facades\Taxonomy;

use function Laravel\Prompts\confirm;
use Illuminate\Console\Command;
use Statamic\Facades\Collection;
use function Laravel\Prompts\info;
use Statamic\Console\RunsInPlease;
use Aerni\Factory\Factories\Factory;
use function Laravel\Prompts\select;
use Illuminate\Support\Facades\File;
use function Laravel\Prompts\confirm;

use Statamic\Events\EntryBlueprintFound;
use Aerni\Factory\Factories\DefinitionGenerator;
use Aerni\Factory\Console\Commands\Concerns\SavesFile;
use Aerni\Factory\Console\Commands\Concerns\GetsRelativePath;
use Statamic\Events\TermBlueprintFound;

class MakeFactory extends Command
{
Expand Down Expand Up @@ -124,6 +126,8 @@ protected function getFactoryClassData(): array

$blueprint = $blueprints->firstWhere('handle', $selectedBlueprint);

$this->fireBlueprintEvent($blueprint);

$classNamespace = Factory::$namespace.collect([$contentType, $selectedContentModel])->map(Str::studly(...))->implode('\\');

$className = str($blueprint)->studly()->append('Factory');
Expand All @@ -144,6 +148,15 @@ protected function getFactoryClassData(): array
];
}

protected function fireBlueprintEvent($blueprint): void
{
match (true) {
Str::contains($blueprint->namespace(), 'collections') => EntryBlueprintFound::dispatch($blueprint),
Str::contains($blueprint->namespace(), 'taxonomies') => TermBlueprintFound::dispatch($blueprint),
default => null,
};
}

protected function generateFactoryFromStub(array $replacements): string
{
return preg_replace(
Expand Down

0 comments on commit d35b878

Please sign in to comment.