From 256dfa1267c363f01e508fcec0cf3a8b61b675c4 Mon Sep 17 00:00:00 2001 From: mychidarko Date: Thu, 6 Oct 2022 03:40:14 +0000 Subject: [PATCH] feat: allow watching single file --- src/ServeCommand.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/ServeCommand.php b/src/ServeCommand.php index a846a69..bb45069 100644 --- a/src/ServeCommand.php +++ b/src/ServeCommand.php @@ -5,6 +5,7 @@ namespace Leaf\Console; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -20,6 +21,7 @@ protected function configure() $this ->setHelp('Start the leaf app server') ->setDescription('Run your Leaf app') + ->addArgument('filename', InputArgument::OPTIONAL, 'The PHP script to run') ->addOption('port', 'p', InputOption::VALUE_OPTIONAL, 'Port to run app on') ->addOption('watch', 'w', InputOption::VALUE_NONE, 'Run your leaf app with hot reloading [experimental]'); } @@ -43,6 +45,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int } } + if ($input->getArgument('filename')) { + $input->setOption('watch', true); + } + if ($input->getOption('watch')) { $leafWatcherInstalled = Utils\Core::commandExists('leaf-watcher'); $node = Utils\Core::findNodeJS(); @@ -79,6 +85,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int $port = $input->getOption('port') ? (int) $input->getOption('port') : 5500; $process = Process::fromShellCommandline("$watcher --exec $leaf serve --port $port", null, null, null, null); + if ($input->getArgument('filename')) { + $filename = $input->getArgument('filename'); + $process = Process::fromShellCommandline("$watcher --exec " . PHP_BINARY . " $filename", null, null, null, null); + } + return $process->run(function ($type, $line) use ($output) { $output->write($line); });