Skip to content

Commit

Permalink
Merge pull request #3 from hammerstonedev/af-debug-command
Browse files Browse the repository at this point in the history
Add debug command
  • Loading branch information
aarondfrancis authored Mar 5, 2021
2 parents add172a + 3fb61ae commit ee27307
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 2 deletions.
66 changes: 66 additions & 0 deletions docs/debugging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

# Debugging

Not sure what's triggering a rebuild? You can use the `airdrop:debug` command to help you diagnose it.

The Debug command will simply print out the JSON object that will be hashed to calculate if a rebuild is needed.

For example, let's imagine your triggers are very, very simple:

```php
ConfigTrigger::class => [
'env' => env('APP_ENV')
],

FileTrigger::class => [
'include' => [
base_path('package-lock.json'),
],
]
```

When you call `aidrop:debug`, the following will be printed to your console:

```json
{
"Hammerstone\\Airdrop\\Triggers\\ConfigTrigger": {
"env": "production"
},
"Hammerstone\\Airdrop\\Triggers\\FileTrigger": {
"package-lock.json": "62f6d1bfc836a1536c4869fe8f78249b"
}
}
```

If you want to narrow it down to a single trigger, you can pass that through with the `--trigger` option:

```bash
php artisan airdrop:debug --trigger=Hammerstone\\Airdrop\\Triggers\\ConfigTrigger
```

Then you'll _only_ get output for the config trigger:
```json
{
"Hammerstone\\Airdrop\\Triggers\\ConfigTrigger": {
"env": "production"
}
}
```

You can write this output to a file and store it somewhere for inspection

```bash
php artisan airdrop:debug > airdrop.json
```

Or you can run it before and after a command you expect is modifying files (as was the case with [this issue](https://github.com/hammerstonedev/airdrop/issues/2)) to see what the difference is:

```bash
php artisan aidrop:debug > before.json

npm run production

php artisan aidrop:debug > after.json

diff before.json after.json
```
3 changes: 2 additions & 1 deletion docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"Filesystem": "/drivers/filesystem",
"Custom": "/drivers/custom"
}
}
},
"Debugging": "/debugging"
}
}
4 changes: 3 additions & 1 deletion src/AirdropServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace Hammerstone\Airdrop;

use Hammerstone\Airdrop\Commands\Debug;
use Hammerstone\Airdrop\Commands\Install;
use Hammerstone\Airdrop\Commands\Download;
use Hammerstone\Airdrop\Commands\Upload;
Expand All @@ -18,7 +19,8 @@ public function boot()
$this->commands([
Install::class,
Download::class,
Upload::class
Upload::class,
Debug::class
]);
}

Expand Down
32 changes: 32 additions & 0 deletions src/Commands/Debug.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* @author Aaron Francis <[email protected]>
*/

namespace Hammerstone\Airdrop\Commands;

use Arr;
use Hammerstone\Airdrop\HashGenerator;
use Illuminate\Console\Command;

class Debug extends Command
{
protected $signature = 'airdrop:debug {--trigger=}';

protected $description = 'Output the array of all triggers, or a specific trigger.';

public function handle()
{
$output = HashGenerator::make()->asArray();

if ($trigger = $this->option('trigger')) {
$output = Arr::only($output, $trigger);
}

// Pretty print it to make diffing easier.
$this->line(
json_encode($output, JSON_PRETTY_PRINT)
);
}

}
66 changes: 66 additions & 0 deletions tests/Commands/DebugCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
* @author Aaron Francis <[email protected]|https://twitter.com/aarondfrancis>
*/

namespace Hammerstone\Airdrop\Tests\Commands;

use Hammerstone\Airdrop\Tests\BaseTest;
use Hammerstone\Airdrop\Triggers\ConfigTrigger;
use Hammerstone\Airdrop\Triggers\FileTrigger;

class DebugCommandTest extends BaseTest
{
public function getEnvironmentSetUp($app)
{
config()->set('airdrop.triggers', [
ConfigTrigger::class => [
'env' => 'testing'
],
FileTrigger::class => [
'trim' => base_path(),
'include' => [
base_path('tests/Support/primary-webpack.mix.example'),
]
]
]);
}

/** @test */
public function test_all_triggers_output()
{
$expected = <<<EOT
{
"Hammerstone\\\Airdrop\\\Triggers\\\ConfigTrigger": {
"env": "testing"
},
"Hammerstone\\\Airdrop\\\Triggers\\\FileTrigger": {
"\/tests\/Support\/primary-webpack.mix.example": "62f6d1bfc836a1536c4869fe8f78249b"
}
}
EOT;

$this->artisan('airdrop:debug')
->expectsOutput($expected)
->assertExitCode(0);
}


/** @test */
public function test_single_trigger()
{
$expected = <<<EOT
{
"Hammerstone\\\Airdrop\\\Triggers\\\ConfigTrigger": {
"env": "testing"
}
}
EOT;

$this->artisan('airdrop:debug --trigger=Hammerstone\\\Airdrop\\\Triggers\\\ConfigTrigger')
->expectsOutput($expected)
->assertExitCode(0);
}


}

0 comments on commit ee27307

Please sign in to comment.