@@ -35,12 +35,18 @@ public function __construct(
3535 protected function configure (): void
3636 {
3737 $ this
38+ ->addOption (
39+ 'watch ' ,
40+ 'w ' ,
41+ InputOption::VALUE_NONE ,
42+ 'Watch mode rebuilds on file change '
43+ )
3844 ->addOption (
3945 'timeout ' ,
4046 't ' ,
4147 InputOption::VALUE_REQUIRED ,
42- ' Timeout in seconds ' ,
43- $ this -> timeout
48+ " Timeout in seconds (default timeout is { $ this -> timeout } s when this option isn't used and not in watch mode) " ,
49+ null
4450 )
4551 ->addOption (
4652 'config-name ' ,
@@ -61,10 +67,16 @@ protected function configure(): void
6167
6268 protected function initialize (InputInterface $ input , OutputInterface $ output ): void
6369 {
70+ $ watch = $ input ->getOption ('watch ' );
6471 $ timeout = $ input ->getOption ('timeout ' );
6572
66- if (!is_numeric ($ timeout )) {
67- throw new InvalidArgumentException ('Timeout value has to be an integer. ' );
73+ if (null !== $ timeout ) {
74+ if ($ watch ) {
75+ throw new InvalidArgumentException ('Watch mode can \'t be used with a timeout. ' );
76+ }
77+ if (!is_numeric ($ timeout )) {
78+ throw new InvalidArgumentException ('Timeout value has to be an integer. ' );
79+ }
6880 }
6981 }
7082
@@ -75,7 +87,8 @@ protected function getFrontendConfigPath(string $configName): string
7587
7688 protected function execute (InputInterface $ input , OutputInterface $ output ): int
7789 {
78- $ timeout = (float )$ input ->getOption ('timeout ' );
90+ $ watch = $ input ->getOption ('watch ' );
91+ $ timeout = $ watch ? null : (float )($ input ->getOption ('timeout ' ) ?? $ this ->timeout );
7992 $ env = $ input ->getOption ('env ' );
8093 $ configName = $ input ->getOption ('config-name ' );
8194 $ frontendConfigsName = $ input ->getOption ('frontend-configs-name ' );
@@ -87,6 +100,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
87100 $ yarnBaseEncoreCommand = "yarn encore {$ encoreEnv }" ;
88101 $ yarnEncoreCommand = $ yarnBaseEncoreCommand ;
89102
103+ if ($ watch ) {
104+ $ yarnEncoreCommand = "{$ yarnBaseEncoreCommand } --watch " ;
105+ }
106+
90107 if (!empty ($ configName )) {
91108 $ yarnEncoreCommand = "{$ yarnBaseEncoreCommand } --config-name {$ configName }" ;
92109 }
0 commit comments