diff --git a/composer.json b/composer.json index 9bc6426..f68022a 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "psr-4": { "kevinquillen\\": "src" } }, "require": { - "drupal/core": "^10", - "drush/drush": "^11 || ^12.4.3" + "drupal/core": ">=11", + "drush/drush": "^13.0" } } diff --git a/src/Drush/Generators/RecipeGenerator.php b/src/Drush/Generators/RecipeGenerator.php index cfaf792..08be6f8 100644 --- a/src/Drush/Generators/RecipeGenerator.php +++ b/src/Drush/Generators/RecipeGenerator.php @@ -4,13 +4,24 @@ namespace kevinquillen\Drush\Generators; -use DrupalCodeGenerator\Command\DrupalGenerator; +use DrupalCodeGenerator\Asset\AssetCollection; +use DrupalCodeGenerator\Command\BaseGenerator; +use DrupalCodeGenerator\Attribute\Generator; +use DrupalCodeGenerator\Validator\Required; use Symfony\Component\Console\Question\Question; +use DrupalCodeGenerator\GeneratorType; /** * Implements Recipe generator command. */ -final class RecipeGenerator extends DrupalGenerator { +#[Generator( + name: 'recipe', + description: 'Generates a recipe', + hidden: true, + type: GeneratorType::OTHER, + templatePath: __DIR__ . '/../../../templates' +)] +final class RecipeGenerator extends BaseGenerator { /** * This is a temporary workaround until Drupal generator supports Recipes. @@ -36,13 +47,6 @@ final class RecipeGenerator extends DrupalGenerator { */ protected string $description = 'Generates a Recipe for adding new functionality to Drupal.'; - /** - * The path to the templates for the generator. - * - * @var string - */ - protected string $templatePath = __DIR__ . '/../../../templates'; - /** * {@inheritdoc} */ @@ -53,20 +57,21 @@ protected function getExtensionList(): array { /** * {@inheritdoc} */ - protected function generate(array &$vars): void { - $vars['recipe_name'] = $this->ask('What is the name of this recipe?', 'My Custom Recipe', '::validateRequired'); - $vars['recipe_directory'] = $this->ask('In what directory should this recipe be saved under /recipes (ex. "my-recipe")?', 'my-custom-recipe', '::validateRequired'); - $vars['recipe_type'] = $this->ask('What type of recipe is this (Site, Content Type, Workflow, etc)?', NULL, '::validateRequired'); - $vars['recipe_description'] = $this->ask('What does this recipe do?', NULL, '::validateRequired'); + protected function generate(array &$vars, AssetCollection $assets): void { + $interviewer = $this->createInterviewer($vars); + $vars['recipe_name'] = $interviewer->ask('What is the name of this recipe?', 'My Custom Recipe', new Required()); + $vars['recipe_directory'] = $interviewer->ask('In what directory should this recipe be saved under /recipes (ex. "my-recipe")?', 'my-custom-recipe', new Required()); + $vars['recipe_type'] = $interviewer->ask('What type of recipe is this (Site, Content Type, Workflow, etc)?', NULL, new Required()); + $vars['recipe_description'] = $interviewer->ask('What does this recipe do?', NULL, new Required()); $vars['composer'] = $this->collectComposerInfo($vars); $vars['modules'] = $this->collectModules($vars); $vars['config'] = $this->collectConfig($vars); if (!empty($vars['composer'])) { - $this->addFile('composer.json', 'composer/composer.json'); + $assets->addFile('composer.json', 'composer/composer.json.twig'); } - $this->addFile('recipe.yml', 'recipe/recipe.yml'); + $assets->addFile('recipe.yml', 'recipe/recipe.yml.twig'); } /** @@ -74,8 +79,8 @@ protected function generate(array &$vars): void { * * This is a temporary workaround until Drupal generator supports Recipes. */ - public function getDestination(array $vars): ?string { - return $this->drupalContext->getDrupalRoot() . '/recipes/custom/' . $vars['recipe_directory']; + protected function getDestination(array $vars): string { + return \DRUPAL_ROOT . '/recipes/custom/' . $vars['recipe_directory']; } /** @@ -89,9 +94,10 @@ public function getDestination(array $vars): ?string { * @return array */ protected function collectComposerInfo(array &$vars, bool $default = TRUE): array { + $interviewer = $this->createInterviewer($vars); $vars['composer'] = []; - if (!$this->confirm('Would you like to add a composer.json file for this recipe? This will let you declare dependencies.', $default)) { + if (!$interviewer->confirm('Would you like to add a composer.json file for this recipe? This will let you declare dependencies.', $default)) { return $vars['composer']; } @@ -139,9 +145,10 @@ protected function collectComposerInfo(array &$vars, bool $default = TRUE): arra * @return array */ protected function collectModules(array &$vars, bool $default = TRUE): array { + $interviewer = $this->createInterviewer($vars); $vars['modules'] = []; - if (!$this->confirm('Would you like to add modules to install for this recipe?', $default)) { + if (!$interviewer->confirm('Would you like to add modules to install for this recipe?', $default)) { return $vars['modules']; } @@ -170,9 +177,10 @@ protected function collectModules(array &$vars, bool $default = TRUE): array { * @return array */ protected function collectConfig(array &$vars, bool $default = TRUE): array { + $interviewer = $this->createInterviewer($vars); $vars['config'] = []; - if ($this->confirm('Would you like to run specific config imports for this recipe?', $default)) { + if ($interviewer->confirm('Would you like to run specific config imports for this recipe?', $default)) { while (TRUE) { $config = []; $question = new Question('What module do you want to import config for (ex. node)?'); @@ -182,7 +190,7 @@ protected function collectConfig(array &$vars, bool $default = TRUE): array { break; } - if (!$this->confirm("Do you want to import all config for $module (including optional config)?", $default)) { + if (!$interviewer->confirm("Do you want to import all config for $module (including optional config)?", $default)) { while (TRUE) { $question = new Question("Enter the config file you want to import for $module (without the .yml extension)."); $filename = $this->io()->askQuestion($question); @@ -202,7 +210,7 @@ protected function collectConfig(array &$vars, bool $default = TRUE): array { } } - if ($this->confirm('Would you like to run config actions for this recipe?', $default)) { + if ($interviewer->confirm('Would you like to run config actions for this recipe?', $default)) { // ask for config actions // ask for action type }