diff --git a/bin/gt b/bin/gt index ccaeb32..c33fc5c 100755 --- a/bin/gt +++ b/bin/gt @@ -24,11 +24,11 @@ $app = new Application( "PHP.Gt Command Line Interface", new ArgumentList(...$argv), new CreateCommand(), - new ServeCommand(), - new BuildCommand(), - new CronCommand(), new RunCommand(), new DeployCommand(), new MigrateCommand(), + new ServeCommand(), + new BuildCommand(), + new CronCommand(), ); $app->run(); diff --git a/composer.lock b/composer.lock index 9f636df..0d2258d 100644 --- a/composer.lock +++ b/composer.lock @@ -204,16 +204,16 @@ }, { "name": "phpgt/build", - "version": "v1.1.0", + "version": "v1.2.0", "source": { "type": "git", "url": "https://github.com/PhpGt/Build.git", - "reference": "2c99952f10e29f5f1716e9cd19e5bb3af276f9b5" + "reference": "09ac7fcbd1188db02ae5b0111a3272e7e96fa2ae" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PhpGt/Build/zipball/2c99952f10e29f5f1716e9cd19e5bb3af276f9b5", - "reference": "2c99952f10e29f5f1716e9cd19e5bb3af276f9b5", + "url": "https://api.github.com/repos/PhpGt/Build/zipball/09ac7fcbd1188db02ae5b0111a3272e7e96fa2ae", + "reference": "09ac7fcbd1188db02ae5b0111a3272e7e96fa2ae", "shasum": "" }, "require": { @@ -243,7 +243,7 @@ "description": "Client-side build system for PHP projects.", "support": { "issues": "https://github.com/PhpGt/Build/issues", - "source": "https://github.com/PhpGt/Build/tree/v1.1.0" + "source": "https://github.com/PhpGt/Build/tree/v1.2.0" }, "funding": [ { @@ -251,7 +251,7 @@ "type": "github" } ], - "time": "2021-09-23T10:22:32+00:00" + "time": "2021-09-30T11:03:35+00:00" }, { "name": "phpgt/cli", @@ -521,16 +521,16 @@ }, { "name": "phpgt/server", - "version": "v1.1.2", + "version": "v1.1.3", "source": { "type": "git", "url": "https://github.com/PhpGt/Server.git", - "reference": "0036669bf35b39c847d1ff66db60b7c35160ea1d" + "reference": "799f18f4cefe70f1305d5272f3f19151bd4c51b2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PhpGt/Server/zipball/0036669bf35b39c847d1ff66db60b7c35160ea1d", - "reference": "0036669bf35b39c847d1ff66db60b7c35160ea1d", + "url": "https://api.github.com/repos/PhpGt/Server/zipball/799f18f4cefe70f1305d5272f3f19151bd4c51b2", + "reference": "799f18f4cefe70f1305d5272f3f19151bd4c51b2", "shasum": "" }, "require": { @@ -554,7 +554,7 @@ "description": "Development HTTP server.", "support": { "issues": "https://github.com/PhpGt/Server/issues", - "source": "https://github.com/PhpGt/Server/tree/v1.1.2" + "source": "https://github.com/PhpGt/Server/tree/v1.1.3" }, "funding": [ { @@ -562,7 +562,7 @@ "type": "github" } ], - "time": "2021-09-23T14:12:28+00:00" + "time": "2021-09-23T14:49:11+00:00" }, { "name": "phpgt/typesafegetter", @@ -752,16 +752,16 @@ }, { "name": "webmozart/glob", - "version": "4.3.0", + "version": "4.4.0", "source": { "type": "git", "url": "https://github.com/webmozarts/glob.git", - "reference": "06358fafde0f32edb4513f4fd88fe113a40c90ee" + "reference": "539b5dbc10021d3f9242e7a9e9b6b37843179e83" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozarts/glob/zipball/06358fafde0f32edb4513f4fd88fe113a40c90ee", - "reference": "06358fafde0f32edb4513f4fd88fe113a40c90ee", + "url": "https://api.github.com/repos/webmozarts/glob/zipball/539b5dbc10021d3f9242e7a9e9b6b37843179e83", + "reference": "539b5dbc10021d3f9242e7a9e9b6b37843179e83", "shasum": "" }, "require": { @@ -769,8 +769,8 @@ "webmozart/path-util": "^2.2" }, "require-dev": { - "phpunit/phpunit": "^8.0", - "symfony/filesystem": "^5.1" + "phpunit/phpunit": "^9.5", + "symfony/filesystem": "^5.3" }, "type": "library", "extra": { @@ -796,9 +796,9 @@ "description": "A PHP implementation of Ant's glob.", "support": { "issues": "https://github.com/webmozarts/glob/issues", - "source": "https://github.com/webmozarts/glob/tree/4.3.0" + "source": "https://github.com/webmozarts/glob/tree/4.4.0" }, - "time": "2021-01-21T06:17:15+00:00" + "time": "2021-10-07T16:13:08+00:00" }, { "name": "webmozart/path-util", @@ -1257,16 +1257,16 @@ }, { "name": "phpdocumentor/type-resolver", - "version": "1.5.0", + "version": "1.5.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "30f38bffc6f24293dadd1823936372dfa9e86e2f" + "reference": "a12f7e301eb7258bb68acd89d4aefa05c2906cae" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/30f38bffc6f24293dadd1823936372dfa9e86e2f", - "reference": "30f38bffc6f24293dadd1823936372dfa9e86e2f", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/a12f7e301eb7258bb68acd89d4aefa05c2906cae", + "reference": "a12f7e301eb7258bb68acd89d4aefa05c2906cae", "shasum": "" }, "require": { @@ -1301,9 +1301,9 @@ "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", "support": { "issues": "https://github.com/phpDocumentor/TypeResolver/issues", - "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.5.0" + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.5.1" }, - "time": "2021-09-17T15:28:14+00:00" + "time": "2021-10-02T14:08:47+00:00" }, { "name": "phpspec/prophecy", @@ -1756,16 +1756,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.5.9", + "version": "9.5.10", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "ea8c2dfb1065eb35a79b3681eee6e6fb0a6f273b" + "reference": "c814a05837f2edb0d1471d6e3f4ab3501ca3899a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/ea8c2dfb1065eb35a79b3681eee6e6fb0a6f273b", - "reference": "ea8c2dfb1065eb35a79b3681eee6e6fb0a6f273b", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c814a05837f2edb0d1471d6e3f4ab3501ca3899a", + "reference": "c814a05837f2edb0d1471d6e3f4ab3501ca3899a", "shasum": "" }, "require": { @@ -1781,7 +1781,7 @@ "phar-io/version": "^3.0.2", "php": ">=7.3", "phpspec/prophecy": "^1.12.1", - "phpunit/php-code-coverage": "^9.2.3", + "phpunit/php-code-coverage": "^9.2.7", "phpunit/php-file-iterator": "^3.0.5", "phpunit/php-invoker": "^3.1.1", "phpunit/php-text-template": "^2.0.3", @@ -1843,7 +1843,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.9" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.10" }, "funding": [ { @@ -1855,7 +1855,7 @@ "type": "github" } ], - "time": "2021-08-31T06:47:40+00:00" + "time": "2021-09-25T07:38:51+00:00" }, { "name": "sebastian/cli-parser", diff --git a/src/Command/CreateCommand.php b/src/Command/CreateCommand.php index 11bdc3e..02b12bb 100644 --- a/src/Command/CreateCommand.php +++ b/src/Command/CreateCommand.php @@ -109,19 +109,9 @@ public function run(ArgumentValueList $arguments = null):void { usleep(500_000); chdir($name); - $process = new Process("gt", "run"); - $process->exec(); - do { - $this->write( - $process->getOutput() - ); - $this->write( - $process->getErrorOutput(), - Stream::ERROR - ); - usleep(1_000_000); - } - while($process->isRunning()); + $runCommand = new RunCommand(); + $runCommand->setStream($this->stream); + $runCommand->run($arguments); } else { $this->writeLine("Your new application is in the '$name' directory."); diff --git a/src/Command/RunCommand.php b/src/Command/RunCommand.php index 4d36752..fbf7cb9 100644 --- a/src/Command/RunCommand.php +++ b/src/Command/RunCommand.php @@ -3,9 +3,76 @@ use Gt\Cli\Argument\ArgumentValueList; use Gt\Cli\Command\Command; +use Gt\Cli\Parameter\Parameter; +use Gt\Cli\Stream; +use Gt\Daemon\Pool; +use Gt\Daemon\Process; class RunCommand extends Command { public function run(ArgumentValueList $arguments = null):void { + global $argv; + + $serveArgs = []; + if($arguments->contains("debug")) { + array_push($serveArgs, "--debug"); + } + $bindValue = $arguments->get("bind", "0.0.0.0"); + array_push($serveArgs, "--bind"); + array_push($serveArgs, $bindValue); + $portValue = $arguments->get("port", "8080"); + array_push($serveArgs, "--port"); + array_push($serveArgs, $portValue); + + $processList = [ + "serve" => new Process( + $argv[0], + "serve", + ...$serveArgs, + ), + ]; + + if(!$arguments->contains("no-build")) { + $processList["build"] = new Process($argv[0], "build", "--watch"); + } + + if(!$arguments->contains("no-cron")) { + $processList["cron"] = new Process($argv[0], "cron", "--watch"); + } + + $pool = new Pool(); + foreach($processList as $name => $process) { + $pool->add($name, $process); + } + + $pool->exec(); + + /** @noinspection HttpUrlsUsage */ + $localUrl = "http://"; + if($bindValue == "0.0.0.0" || $bindValue == "127.0.0.1") { + $localUrl .= "localhost"; + } + else { + $localUrl .= $bindValue; + } + + if($portValue != "80") { + $localUrl .= ":$portValue"; + } + + usleep(100_000); + if($processList["serve"]->isRunning()) { + $this->writeLine("To view your application in your browser, visit: $localUrl"); + $this->writeLine("To stop running, press [CTRL]+[C]."); + $this->writeLine(); + } + + do { + $this->write($pool->read()); + $this->write($pool->read(Process::PIPE_ERROR), Stream::ERROR); + usleep(100_000); + } + while($processList["serve"]->isRunning()); + $this->writeLine("The server process has ended."); } public function getName():string { @@ -29,6 +96,30 @@ public function getRequiredParameterList():array { } public function getOptionalParameterList():array { - return []; + return [ + new Parameter( + true, + "port", + "p" + ), + new Parameter( + true, + "bind", + "b" + ), + new Parameter( + false, + "debug", + "d" + ), + new Parameter( + false, + "no-build" + ), + new Parameter( + false, + "no-cron" + ) + ]; } }