Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up and normalize console command classes #598

Merged
merged 15 commits into from
Oct 26, 2022
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
/**
* Hyde command to run the build process for the RSS feed.
*
* @see \Hyde\Framework\Testing\Feature\Commands\HydeBuildRssFeedCommandTest
* @see \Hyde\Framework\Testing\Feature\Commands\BuildRssFeedCommandTest
*/
class BuildRssFeedCommand extends Command
{
/** @var string */
protected $signature = 'build:rss';

/** @var string */
protected $description = 'Generate the RSS feed';

public function handle(): int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
/**
* Hyde command to run the build process for the documentation search index.
*
* @see \Hyde\Framework\Testing\Feature\Commands\HydeBuildSearchCommandTest
* @see \Hyde\Framework\Testing\Feature\Commands\BuildSearchCommandTest
*/
class BuildSearchCommand extends Command
{
/** @var string */
protected $signature = 'build:search';

/** @var string */
protected $description = 'Generate the docs/search.json';

public function handle(): int
Expand Down
28 changes: 2 additions & 26 deletions packages/framework/src/Console/Commands/BuildSiteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Hyde\Console\Commands;

use Exception;
use Hyde\Framework\Actions\PostBuildTasks\GenerateRssFeed;
use Hyde\Framework\Actions\PostBuildTasks\GenerateSearch;
use Hyde\Framework\Actions\PostBuildTasks\GenerateSitemap;
Expand All @@ -23,34 +22,19 @@
*/
class BuildSiteCommand extends Command
{
/**
* The signature of the command.
*
* @var string
*/
/** @var string */
protected $signature = 'build
{--run-dev : Run the NPM dev script after build}
{--run-prod : Run the NPM prod script after build}
{--run-prettier : Format the output using NPM Prettier}
{--pretty-urls : Should links in output use pretty URLs?}
{--no-api : Disable API calls, for example, Torchlight}';

/**
* The description of the command.
*
* @var string
*/
/** @var string */
protected $description = 'Build the static site';

protected BuildService $service;

/**
* Execute the console command.
*
* @return int
*
* @throws Exception
*/
public function handle(): int
{
$time_start = microtime(true);
Expand All @@ -74,7 +58,6 @@ public function handle(): int
return 0;
}

/** @internal */
protected function runPreBuildActions(): void
{
if ($this->option('no-api')) {
Expand All @@ -92,11 +75,6 @@ protected function runPreBuildActions(): void
}
}

/**
* Run any post-build actions.
*
* @return void
*/
public function runPostBuildActions(): void
{
$service = new BuildTaskService($this->output);
Expand Down Expand Up @@ -124,7 +102,6 @@ public function runPostBuildActions(): void
$service->runPostBuildTasks();
}

/** @internal */
protected function printFinishMessage(float $time_start): void
{
$execution_time = (microtime(true) - $time_start);
Expand All @@ -141,7 +118,6 @@ protected function printFinishMessage(float $time_start): void
);
}

/* @internal */
protected function runNodeCommand(string $command, string $message, ?string $actionMessage = null): void
{
$this->info($message.' This may take a second.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* Hyde command to run the build process for the sitemap.
*
* @see \Hyde\Framework\Testing\Feature\Commands\HydeBuildSitemapCommandTest
* @see \Hyde\Framework\Testing\Feature\Commands\BuildSitemapCommandTest
*/
class BuildSitemapCommand extends Command
{
Expand Down
17 changes: 2 additions & 15 deletions packages/framework/src/Console/Commands/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,10 @@
*/
class DebugCommand extends Command
{
/**
* The signature of the command.
*
* @var string
*/
/** @var string */
protected $signature = 'debug';

/**
* The description of the command.
*
* @var string
*/
/** @var string */
protected $description = 'Print debug info';

public function __construct()
Expand All @@ -36,11 +28,6 @@ public function __construct()
}
}

/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
$this->info('HydePHP Debug Screen');
Expand Down
29 changes: 3 additions & 26 deletions packages/framework/src/Console/Commands/MakePageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,19 @@
/**
* Hyde Command to scaffold a new Markdown or Blade page file.
*
* @see \Hyde\Framework\Testing\Feature\Commands\HydeMakePageCommandTest
* @see \Hyde\Framework\Testing\Feature\Commands\MakePageCommandTest
*/
class MakePageCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
/** @var string */
protected $signature = 'make:page
{title? : The name of the page file to create. Will be used to generate the slug}
{--type=markdown : The type of page to create (markdown, blade, or docs)}
{--blade : Create a Blade page}
{--docs : Create a Documentation page}
{--force : Overwrite any existing files}';

/**
* The console command description.
*
* @var string
*/
/** @var string */
protected $description = 'Scaffold a new Markdown, Blade, or documentation page file';

/**
Expand All @@ -57,9 +49,6 @@ class MakePageCommand extends Command
*/
public bool $force;

/**
* Execute the console command.
*/
public function handle(): int
{
$this->title('Creating a new page!');
Expand All @@ -81,13 +70,6 @@ public function handle(): int
return 0;
}

/**
* Validate the options passed to the command.
*
* @return void
*
* @throws UnsupportedPageTypeException if the page type is invalid.
*/
protected function validateOptions(): void
{
$type = $this->getSelectedType();
Expand All @@ -112,11 +94,6 @@ protected function validateOptions(): void
throw new UnsupportedPageTypeException("Invalid page type: $type");
}

/**
* Get the selected page type.
*
* @return string
*/
protected function getSelectedType(): string
{
$type = 'markdown';
Expand Down
17 changes: 2 additions & 15 deletions packages/framework/src/Console/Commands/MakePostCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,14 @@
*/
class MakePostCommand extends Command
{
/**
* The signature of the command.
*
* @var string
*/
/** @var string */
protected $signature = 'make:post
{title? : The title for the Post. Will be used to generate the slug}
{--force : Should the generated file overwrite existing posts with the same slug?}';

/**
* The description of the command.
*
* @var string
*/
/** @var string */
protected $description = 'Scaffold a new Markdown blog post file';

/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
$this->title('Creating a new post!');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
use Illuminate\Foundation\PackageManifest;

/**
* @see \Hyde\Framework\Testing\Feature\Commands\HydePackageDiscoverCommandTest
* @see \Hyde\Framework\Testing\Feature\Commands\PackageDiscoverCommandTest
*/
class PackageDiscoverCommand extends BaseCommand
{
/** @var true */
protected $hidden = true;

public function handle(PackageManifest $manifest)
public function handle(PackageManifest $manifest): void
{
$manifest->manifestPath = Hyde::path('storage/framework/cache/packages.php');
parent::handle($manifest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/**
* Publish one of the default homepages.
*
* @see \Hyde\Framework\Testing\Feature\Commands\HydePublishHomepageCommandTest
* @see \Hyde\Framework\Testing\Feature\Commands\PublishHomepageCommandTest
*/
class PublishHomepageCommand extends Command
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,15 @@
/**
* Hyde Command to build a single static site file.
*
* @see \Hyde\Framework\Testing\Feature\Commands\HydeRebuildStaticSiteCommandTest
* @see \Hyde\Framework\Testing\Feature\Commands\RebuildStaticSiteCommandTest
*/
class RebuildStaticSiteCommand extends Command
{
/**
* The signature of the command.
*
* @var string
*/
/** @var string */
protected $signature = 'rebuild
{path : The relative file path (example: _posts/hello-world.md)}';

/**
* The description of the command.
*
* @var string
*/
/** @var string */
protected $description = 'Run the static site builder for a single file';

/**
Expand All @@ -40,11 +32,6 @@ class RebuildStaticSiteCommand extends Command
*/
public string $path;

/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
$time_start = microtime(true);
Expand Down
5 changes: 4 additions & 1 deletion packages/framework/src/Console/Commands/RouteListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
/**
* Hyde command to display the list of site routes.
*
* @see \Hyde\Framework\Testing\Feature\Commands\HydeRouteListCommandTest
* @see \Hyde\Framework\Testing\Feature\Commands\RouteListCommandTest
*/
class RouteListCommand extends Command
{
/** @var string */
protected $signature = 'route:list';

/** @var string */
protected $description = 'Display all registered routes.';

public function handle(): int
Expand Down
17 changes: 2 additions & 15 deletions packages/framework/src/Console/Commands/ServeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,12 @@
*/
class ServeCommand extends Command
{
/**
* The signature of the command.
*
* @var string
*/
/** @var string */
protected $signature = 'serve {--port=8080} {--host=localhost}';

/**
* The description of the command.
*
* @var string
*/
/** @var string */
protected $description = 'Start the experimental realtime compiler.';

/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
$this->line('<info>Starting the HydeRC server...</info> Press Ctrl+C to stop');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* Publish the Hyde Config Files.
*
* @see \Hyde\Framework\Testing\Feature\Commands\HydeUpdateConfigsCommandTest
* @see \Hyde\Framework\Testing\Feature\Commands\UpdateConfigsCommandTest
*/
class UpdateConfigsCommand extends Command
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use LaravelZero\Framework\Commands\Command;

/**
* @see \Hyde\Framework\Testing\Feature\Commands\HydeValidateCommandTest
* @see \Hyde\Framework\Testing\Feature\Commands\ValidateCommandTest
*/
class ValidateCommand extends Command
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ abstract class AbstractBuildTask implements BuildTaskContract
protected static string $description = 'Generic build task';

protected float $timeStart;

/**
* @todo Consider setting default value to 0
*/
protected ?int $exitCode = null;

public function __construct(?OutputStyle $output = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/**
* @see \Hyde\Framework\Testing\Feature\Services\ValidationServiceTest
* @see \Hyde\Framework\Testing\Feature\Commands\HydeValidateCommandTest
* @see \Hyde\Framework\Testing\Feature\Commands\ValidateCommandTest
*/
class ValidationResult
{
Expand Down
Loading