-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from hammerstonedev/af-debug-command
Add debug command
- Loading branch information
Showing
5 changed files
with
169 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
"Filesystem": "/drivers/filesystem", | ||
"Custom": "/drivers/custom" | ||
} | ||
} | ||
}, | ||
"Debugging": "/debugging" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
|
||
} |