Skip to content

Commit 3f41cd0

Browse files
committed
feat: add ui command
1 parent c5f9af2 commit 3f41cd0

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

bin/leaf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ $app->add(new Leaf\Console\ServeCommand);
2727
$app->add(new Leaf\Console\DeployCommand);
2828
$app->add(new Leaf\Console\InteractCommand);
2929
$app->add(new Leaf\Console\RunCommand);
30+
$app->add(new Leaf\Console\UICommand);
3031
$app->add(new Leaf\Console\ViewBuildCommand);
3132
$app->add(new Leaf\Console\ViewDevCommand);
3233
$app->add(new Leaf\Console\ViewInstallCommand);

src/UICommand.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Leaf\Console;
6+
7+
use Symfony\Component\Console\Command\Command;
8+
use Symfony\Component\Console\Input\InputArgument;
9+
use Symfony\Component\Console\Input\InputOption;
10+
use Symfony\Component\Console\Input\InputInterface;
11+
use Symfony\Component\Console\Output\OutputInterface;
12+
use Symfony\Component\Console\Question\ConfirmationQuestion;
13+
use Symfony\Component\Process\Process;
14+
15+
class UICommand extends Command
16+
{
17+
protected static $defaultName = 'ui';
18+
19+
protected function configure()
20+
{
21+
$this
22+
->setHelp('Open up the Leaf CLI GUI')
23+
->setDescription('Start the Leaf CLI GUI process')
24+
->addOption('port', 'p', InputOption::VALUE_OPTIONAL, 'Port to run app on');
25+
}
26+
27+
protected function execute(InputInterface $input, OutputInterface $output): int
28+
{
29+
$port = $input->getOption('port') ? (int) $input->getOption('port') : 5500;
30+
$uiDirectory = __DIR__ . '/ui/dist';
31+
32+
$serveCommand = "cd $uiDirectory && php -S localhost:$port";
33+
34+
$process = Process::fromShellCommandline(
35+
$serveCommand,
36+
null,
37+
null,
38+
null,
39+
null
40+
);
41+
42+
$output->writeln("<info>CLI GUI started at <href=http://localhost:$port>http://localhost:$port</></info>");
43+
44+
return $process->run(function ($type, $line) use ($output, $process) {
45+
if (is_string($line) && !strpos($line, 'Failed')) {
46+
$output->write($line);
47+
} else {
48+
$output->write("<error>$line</error>");
49+
}
50+
});
51+
}
52+
}

src/ui/dist/server.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
header('Access-Control-Allow-Origin: *');
77
header('Access-Control-Allow-Headers: *');
88

9-
require __DIR__ . '/vendor/autoload.php';
9+
require dirname(__DIR__) . '/vendor/autoload.php';
1010

1111
$action = $_GET['action'] ?? null;
1212

0 commit comments

Comments
 (0)