Skip to content

Commit c4f5753

Browse files
committed
feat: add docker compose to leaf serve
1 parent 865d7da commit c4f5753

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/ServeCommand.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,22 @@ protected function askToInstallWatcher($input, $output)
109109
protected function startServer(InputInterface $input, OutputInterface $output): int
110110
{
111111
$port = $input->getOption('port') ? (int) $input->getOption('port') : 5500;
112-
$process = Process::fromShellCommandline("php -S localhost:$port", null, null, null, null);
113-
114-
$output->writeln("<info>Starting Leaf development server on <href=http://localhost:$port>http://localhost:$port</></info>");
115-
116-
return $process->run(function ($type, $line) use ($output, $port) {
112+
$isDockerProject = file_exists(getcwd() . '/docker-compose.yml');
113+
$process = Process::fromShellCommandline(
114+
$isDockerProject ? 'docker-compose up' : "php -S localhost:$port",
115+
null,
116+
null,
117+
null,
118+
null
119+
);
120+
121+
$output->writeln(
122+
$isDockerProject ?
123+
'<info>Serving Leaf application using docker-compose...</info>' :
124+
"<info>Starting Leaf development server on <href=http://localhost:$port>http://localhost:$port</></info>"
125+
);
126+
127+
return $process->run(function ($type, $line) use ($output, $process) {
117128
if (is_string($line) && !strpos($line, 'Failed')) {
118129
$output->write($line);
119130
} else {

0 commit comments

Comments
 (0)