Skip to content

Commit

Permalink
feat: allow watching single file
Browse files Browse the repository at this point in the history
  • Loading branch information
mychidarko committed Oct 6, 2022
1 parent 1c09462 commit 256dfa1
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/ServeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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]');
}
Expand All @@ -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();
Expand Down Expand Up @@ -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);
});
Expand Down

0 comments on commit 256dfa1

Please sign in to comment.