Skip to content

Commit

Permalink
Merge pull request #47 from RyanNerd/fix-eject
Browse files Browse the repository at this point in the history
Fix 🔧 command
  • Loading branch information
RyanNerd committed Jun 13, 2021
2 parents 86dc270 + faf4f4d commit 8b96b55
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 6 deletions.
66 changes: 66 additions & 0 deletions app/Robo/Plugin/Commands/EjectCommands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);

namespace Willow\Robo\Plugin\Commands;

use League\CLImate\TerminalObject\Dynamic\Input;
use Twig\Environment as Twig;
use Twig\Loader\FilesystemLoader;

class EjectCommands extends RoboBase
{
private const CONTROLLERS_PATH = __DIR__ . '/../../../Controllers/';

/**
* 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 = self::CONTROLLERS_PATH . 'Sample';
array_map('unlink', glob("$sampleDirPath/*.*"));
if (file_exists($sampleDirPath)) {
if (is_dir($sampleDirPath)) {
rmdir($sampleDirPath);
}
}

// Get a file list of any controllers
$dirList = glob(self::CONTROLLERS_PATH . '*', GLOB_ONLYDIR);
// No need to register controllers if there are none.
if ($dirList === false || count($dirList) === 0) {
$cli->lightYellow('INFO: No controllers exist to re-register');
} else {
// Rebuild RegisterControllers.php
$loader = new FilesystemLoader(__DIR__ . '/Templates');
$twig = new Twig($loader);
$registerControllers = new RegisterForge($twig);
$registerControllers->forgeRegisterControllers();
}
}
}
12 changes: 6 additions & 6 deletions app/Robo/Plugin/Commands/RoboBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ abstract class RoboBase extends Tasks
*/
protected static $willowContainer;

protected const ENV_ERROR = 'Unable to create the .env file. You may need to create this manually.';
protected const CONFIG_PATH = __DIR__ . '/../../../../config/';
protected const ENV_PATH = __DIR__ . '/../../../../.env';
protected const TEMPLATE_PATH = __DIR__ . '/Templates';
protected const MODELS_PATH = __DIR__ . '/../../../Robo/../Models/';
protected const CONTROLLERS_PATH = __DIR__ . '/../../../Robo/../Controllers/';
private const ENV_ERROR = 'Unable to create the .env file. You may need to create this manually.';
private const CONFIG_PATH = __DIR__ . '/../../../../config/';
private const ENV_PATH = __DIR__ . '/../../../../.env';
private const TEMPLATE_PATH = __DIR__ . '/Templates';
private const MODELS_PATH = __DIR__ . '/../../../Robo/../Models/';
private const CONTROLLERS_PATH = __DIR__ . '/../../../Robo/../Controllers/';

use EnvSetupTrait;

Expand Down

0 comments on commit 8b96b55

Please sign in to comment.