From d3b638da5c38829635b7fea428f2e4ae118dca0a Mon Sep 17 00:00:00 2001 From: Cyril Lussiana Date: Thu, 23 May 2024 22:30:12 +0200 Subject: [PATCH 1/4] Add --poll-watch option --- src/Command/TailwindBuildCommand.php | 2 ++ src/TailwindBuilder.php | 6 +++++- tests/TailwindBuilderTest.php | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Command/TailwindBuildCommand.php b/src/Command/TailwindBuildCommand.php index 994318a..12548b4 100644 --- a/src/Command/TailwindBuildCommand.php +++ b/src/Command/TailwindBuildCommand.php @@ -33,6 +33,7 @@ protected function configure(): void { $this ->addOption('watch', 'w', null, 'Watch for changes and rebuild automatically') + ->addOption('poll-watch', null, null, 'Watch for changes and rebuild automatically (with --poll flag)') ->addOption('minify', 'm', InputOption::VALUE_NONE, 'Minify the output CSS') ; } @@ -44,6 +45,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $process = $this->tailwindBuilder->runBuild( watch: $input->getOption('watch'), + pollWatch: $input->getOption('poll-watch'), minify: $input->getOption('minify'), ); $process->wait(function ($type, $buffer) use ($io) { diff --git a/src/TailwindBuilder.php b/src/TailwindBuilder.php index 1a19794..3cb1f36 100644 --- a/src/TailwindBuilder.php +++ b/src/TailwindBuilder.php @@ -48,18 +48,22 @@ public function __construct( public function runBuild( bool $watch, + bool $pollWatch, bool $minify, ): Process { $binary = $this->createBinary(); $arguments = ['-c', $this->configPath, '-i', $this->inputPath, '-o', $this->getInternalOutputCssPath()]; if ($watch) { $arguments[] = '--watch'; + } elseif ($pollWatch) { + $arguments[] = '--watch'; + $arguments[] = '--poll'; } if ($minify) { $arguments[] = '--minify'; } $process = $binary->createProcess($arguments); - if ($watch) { + if ($watch || $pollWatch) { $process->setTimeout(null); // setting an input stream causes the command to "wait" for the watch $inputStream = new InputStream(); diff --git a/tests/TailwindBuilderTest.php b/tests/TailwindBuilderTest.php index 076b42c..242ba3c 100644 --- a/tests/TailwindBuilderTest.php +++ b/tests/TailwindBuilderTest.php @@ -46,7 +46,7 @@ public function testIntegrationWithDefaultOptions(): void null, __DIR__.'/fixtures/tailwind.config.js' ); - $process = $builder->runBuild(watch: false, minify: false); + $process = $builder->runBuild(watch: false, pollWatch: false, minify: false); $process->wait(); $this->assertTrue($process->isSuccessful()); @@ -67,7 +67,7 @@ public function testIntegrationWithMinify(): void null, __DIR__.'/fixtures/tailwind.config.js' ); - $process = $builder->runBuild(watch: false, minify: true); + $process = $builder->runBuild(watch: false, pollWatch: false, minify: true); $process->wait(); $this->assertTrue($process->isSuccessful()); From bc8cd519c7b5e3cd46486aa927bebb566a311311 Mon Sep 17 00:00:00 2001 From: Cyril Lussiana Date: Thu, 23 May 2024 22:54:29 +0200 Subject: [PATCH 2/4] --poll-watch option documentation --- doc/index.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/doc/index.rst b/doc/index.rst index 6341bf5..e60900e 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -54,6 +54,17 @@ That's it! This will watch for changes to your ``assets/styles/app.css`` file and automatically recompile it when needed. If you refresh the page, the final ``app.css`` file will already contain the compiled CSS. +Watch mode in Docker with Windows host +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +If you work on Windows and your app is running in a Docker container, and you +are having trouble with the ``--watch`` option, you can try runnig the ``tailwind:build`` +command with ``--poll-watch`` option. + +.. code-block:: terminal + + $ php bin/console tailwind:build --poll-watch + Symfony CLI ~~~~~~~~~~~ From 5e7b06034b019cf4b0dd78304737b0a4c84a7a08 Mon Sep 17 00:00:00 2001 From: Cyril Lussiana Date: Fri, 24 May 2024 12:56:13 +0200 Subject: [PATCH 3/4] Adding --poll option --- doc/index.rst | 4 ++-- src/Command/TailwindBuildCommand.php | 4 ++-- src/TailwindBuilder.php | 10 +++++----- tests/TailwindBuilderTest.php | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/doc/index.rst b/doc/index.rst index e60900e..a235851 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -59,11 +59,11 @@ Watch mode in Docker with Windows host If you work on Windows and your app is running in a Docker container, and you are having trouble with the ``--watch`` option, you can try runnig the ``tailwind:build`` -command with ``--poll-watch`` option. +command with ``--poll`` option. .. code-block:: terminal - $ php bin/console tailwind:build --poll-watch + $ php bin/console tailwind:build --watch --poll Symfony CLI ~~~~~~~~~~~ diff --git a/src/Command/TailwindBuildCommand.php b/src/Command/TailwindBuildCommand.php index 12548b4..63e1375 100644 --- a/src/Command/TailwindBuildCommand.php +++ b/src/Command/TailwindBuildCommand.php @@ -33,7 +33,7 @@ protected function configure(): void { $this ->addOption('watch', 'w', null, 'Watch for changes and rebuild automatically') - ->addOption('poll-watch', null, null, 'Watch for changes and rebuild automatically (with --poll flag)') + ->addOption('poll', null, null, 'Apply --poll flag to the command') ->addOption('minify', 'm', InputOption::VALUE_NONE, 'Minify the output CSS') ; } @@ -45,7 +45,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $process = $this->tailwindBuilder->runBuild( watch: $input->getOption('watch'), - pollWatch: $input->getOption('poll-watch'), + poll: $input->getOption('poll'), minify: $input->getOption('minify'), ); $process->wait(function ($type, $buffer) use ($io) { diff --git a/src/TailwindBuilder.php b/src/TailwindBuilder.php index 3cb1f36..305c769 100644 --- a/src/TailwindBuilder.php +++ b/src/TailwindBuilder.php @@ -48,22 +48,22 @@ public function __construct( public function runBuild( bool $watch, - bool $pollWatch, + bool $poll, bool $minify, ): Process { $binary = $this->createBinary(); $arguments = ['-c', $this->configPath, '-i', $this->inputPath, '-o', $this->getInternalOutputCssPath()]; if ($watch) { $arguments[] = '--watch'; - } elseif ($pollWatch) { - $arguments[] = '--watch'; - $arguments[] = '--poll'; + if ($poll) { + $arguments[] = '--poll'; + } } if ($minify) { $arguments[] = '--minify'; } $process = $binary->createProcess($arguments); - if ($watch || $pollWatch) { + if ($watch) { $process->setTimeout(null); // setting an input stream causes the command to "wait" for the watch $inputStream = new InputStream(); diff --git a/tests/TailwindBuilderTest.php b/tests/TailwindBuilderTest.php index 242ba3c..5426888 100644 --- a/tests/TailwindBuilderTest.php +++ b/tests/TailwindBuilderTest.php @@ -46,7 +46,7 @@ public function testIntegrationWithDefaultOptions(): void null, __DIR__.'/fixtures/tailwind.config.js' ); - $process = $builder->runBuild(watch: false, pollWatch: false, minify: false); + $process = $builder->runBuild(watch: false, poll: false, minify: false); $process->wait(); $this->assertTrue($process->isSuccessful()); @@ -67,7 +67,7 @@ public function testIntegrationWithMinify(): void null, __DIR__.'/fixtures/tailwind.config.js' ); - $process = $builder->runBuild(watch: false, pollWatch: false, minify: true); + $process = $builder->runBuild(watch: false, poll: false, minify: true); $process->wait(); $this->assertTrue($process->isSuccessful()); From 6d6ab1634759107abf38bbd8cff9df8f9605fa81 Mon Sep 17 00:00:00 2001 From: Cyril Lussiana Date: Fri, 24 May 2024 14:39:51 +0200 Subject: [PATCH 4/4] Update --poll option description Co-authored-by: Victor Bocharsky --- src/Command/TailwindBuildCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Command/TailwindBuildCommand.php b/src/Command/TailwindBuildCommand.php index 63e1375..e8e505d 100644 --- a/src/Command/TailwindBuildCommand.php +++ b/src/Command/TailwindBuildCommand.php @@ -33,7 +33,7 @@ protected function configure(): void { $this ->addOption('watch', 'w', null, 'Watch for changes and rebuild automatically') - ->addOption('poll', null, null, 'Apply --poll flag to the command') + ->addOption('poll', null, null, 'Use polling instead of filesystem events when watching') ->addOption('minify', 'm', InputOption::VALUE_NONE, 'Minify the output CSS') ; }