Skip to content

Commit

Permalink
feat: improve rockshell api and add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed Feb 11, 2024
1 parent b0137bb commit 6194f19
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
7 changes: 7 additions & 0 deletions RockMigrations.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use RockMigrations\MagicPages;
use RockMigrations\WatchFile;
use RockPageBuilder\Block as RockPageBuilderBlock;
use RockShell\Application;
use Symfony\Component\Yaml\Yaml;
use TracyDebugger;

Expand Down Expand Up @@ -3508,6 +3509,12 @@ protected function resetCachesOnSave(HookEvent $event): void
foreach ($caches as $name) $this->wire->cache->delete($name);
}

public function rockshell(): Application
{
require_once $this->wire->config->paths->root . "RockShell/rock.php";
return $app;
}

/**
* Get version number from package.json in PW root folder
*/
Expand Down
51 changes: 51 additions & 0 deletions docs/rockshell/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# RockShell Integration

You can load RockShell or any registered RockShell command directly from RockMigrations.

## Use Case

Imagine you are developing a command for RockShell. While developing you want to quickly iterate and see if what you are coding is actually working, right? You could code, then fire the command in the console, then code, then fire the command again...

That's not fun and you lose all the great dumping and debugging that you get from TracyDebugger.

As of now there is a better way!

## Loading Commands in site/ready.php

Let's say we had this command in `/site/modules/Site/RockShell/Commands/SiteDoSomething.php`:

```php
<?php

namespace Site;

use RockShell\Command;

class SiteDoSomething extends Command
{
public function handle()
{
$this->doSomething();
return self::SUCCESS;
}

public function doSomething(): void
{
// do something

// log when not in CLI
if(!$this->isCLI()) bd("I'm doing something!");
}
}
```

While developing you could add this to `ready.php` and when using LiveReload you'll get results whenever you save your file without ever leaving your IDE!

```php
rockmigrations()
->rockshell()
->get("site:do:something")
->doSomething();
```

Once you are done and everything works as expected you can simply execute your command from the command line!

0 comments on commit 6194f19

Please sign in to comment.