|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Storybook\Maker; |
| 4 | + |
| 5 | +use Symfony\Bundle\MakerBundle\ConsoleStyle; |
| 6 | +use Symfony\Bundle\MakerBundle\DependencyBuilder; |
| 7 | +use Symfony\Bundle\MakerBundle\Generator; |
| 8 | +use Symfony\Bundle\MakerBundle\InputConfiguration; |
| 9 | +use Symfony\Bundle\MakerBundle\Maker\AbstractMaker; |
| 10 | +use Symfony\Component\Console\Command\Command; |
| 11 | +use Symfony\Component\Console\Input\InputArgument; |
| 12 | +use Symfony\Component\Console\Input\InputInterface; |
| 13 | +use Symfony\Component\Console\Question\Question; |
| 14 | + |
| 15 | +/** |
| 16 | + * @method string getCommandDescription() |
| 17 | + */ |
| 18 | +class MakeStory extends AbstractMaker |
| 19 | +{ |
| 20 | + public function __construct( |
| 21 | + private StoryRenderer $storyRenderer, |
| 22 | + ) { |
| 23 | + } |
| 24 | + |
| 25 | + public static function getCommandName(): string |
| 26 | + { |
| 27 | + return 'make:storybook:story'; |
| 28 | + } |
| 29 | + |
| 30 | + public static function getCommandDescription(): string |
| 31 | + { |
| 32 | + return 'Creates a new Storybook story'; |
| 33 | + } |
| 34 | + |
| 35 | + public function configureCommand(Command $command, InputConfiguration $inputConfig): void |
| 36 | + { |
| 37 | + $command |
| 38 | + ->addArgument('component', InputArgument::OPTIONAL, 'The name of the component you want a story for') |
| 39 | + ; |
| 40 | + } |
| 41 | + |
| 42 | + public function interact(InputInterface $input, ConsoleStyle $io, Command $command): void |
| 43 | + { |
| 44 | + if (null === $input->getArgument('component')) { |
| 45 | + $question = new Question('What is the name of the component?'); |
| 46 | + $question->setValidator(fn ($value) => null !== $value); |
| 47 | + $question->setMaxAttempts(3); |
| 48 | + $input->setArgument('component', $io->askQuestion($question)); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator) |
| 53 | + { |
| 54 | + $componentName = $input->getArgument('component'); |
| 55 | + |
| 56 | + $this->storyRenderer->render($componentName); |
| 57 | + } |
| 58 | + |
| 59 | + public function configureDependencies(DependencyBuilder $dependencies) |
| 60 | + { |
| 61 | + } |
| 62 | +} |
0 commit comments