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