Skip to content

Commit

Permalink
Merge pull request #48 from RyanNerd/sample-command-refactor
Browse files Browse the repository at this point in the history
Sample command refactor 🚧
  • Loading branch information
RyanNerd authored Jun 13, 2021
2 parents 8b96b55 + 44a65ca commit 29d2c16
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 56 deletions.
8 changes: 7 additions & 1 deletion app/Robo/Plugin/Commands/EjectCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ final public function eject(): void {
die();
}

// Destroy the files in the Controllers/Sample directory and the Controllers/Sample directory itself
$sampleDirPath = self::CONTROLLERS_PATH . 'Sample';
array_map('unlink', glob("$sampleDirPath/*.*"));
if (file_exists($sampleDirPath)) {
Expand All @@ -50,7 +51,12 @@ final public function eject(): void {
}
}

// Get a file list of any controllers
// Remove the SampleCommands.php file if it exists
if (file_exists(__DIR__ . '/SampleCommands.php')) {
unlink(__DIR__ . '/SampleCommands.php');
}

// Get a file list of any controllers in the Controllers directory
$dirList = glob(self::CONTROLLERS_PATH . '*', GLOB_ONLYDIR);
// No need to register controllers if there are none.
if ($dirList === false || count($dirList) === 0) {
Expand Down
42 changes: 0 additions & 42 deletions app/Robo/Plugin/Commands/MakeCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,46 +222,4 @@ final public function reset(): void {
RoboBase::showThrowableAndDie($e);
}
}

/**
* Remove Sample controller, routes, & other artifacts from the project
*/
final public function eject(): void {
$cli = $this->cli;
$cli->br();
$cli
->bold()
->backgroundLightRed()
->white()
->border('*');
$cli
->bold()
->backgroundLightRed()
->white('eject is a destructive operation. It removes the Sample controller, route, etc.');
$cli
->bold()
->backgroundLightRed()
->white('It will also overwrite the RegisterControllers.php file.');
$cli
->bold()
->backgroundLightRed()
->white()
->border('*');
$cli->br();
/** @var Input $input */
$input = $cli->bold()->lightGray()->confirm('Are you sure you want to proceed?');
if (!$input->confirmed()) {
die();
}

$sampleDirPath = __DIR__ . '/../../../Controllers/Sample';
array_map('unlink', glob("$sampleDirPath/*.*"));
unlink($sampleDirPath);

// Rebuild RegisterControllers.php
$loader = new FilesystemLoader(__DIR__ . '/Templates');
$twig = new Twig($loader);
$registerControllers = new RegisterForge($twig);
$registerControllers->forgeRegisterControllers();
}
}
20 changes: 20 additions & 0 deletions app/Robo/Plugin/Commands/SampleCommands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
declare(strict_types=1);

namespace Willow\Robo\Plugin\Commands;

class SampleCommands extends RoboBase
{
/**
* Launch the built-in PHP server and load the Sample in a web browser
*/
final public function sample(): void {
$this->taskServer(8088)
->host('127.0.0.1')
->dir(__DIR__ . '/../../../../public')
->background()
->run();
$this->taskOpenBrowser('http://localhost:8088/v1/sample/Hello-World')->run();
sleep(15);
}
}
13 changes: 0 additions & 13 deletions app/Robo/Plugin/Commands/WillowCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,6 @@ final public function docs(): void {
$this->taskOpenBrowser('https://www.notion.so/ryannerd/Get-Started-bf56317580884ccd95ed8d3889f83c72')->run();
}

/**
* Launch the built-in PHP server and load the Sample in a web browser
*/
final public function sample(): void {
$this->taskServer(8088)
->host('127.0.0.1')
->dir(__DIR__ . '/../../../../public')
->background()
->run();
$this->taskOpenBrowser('http://localhost:8088/v1/sample/Hello-World')->run();
sleep(15);
}

/**
* Show Willow's fancy banner
*/
Expand Down

0 comments on commit 29d2c16

Please sign in to comment.