Airdrop — Speed up your Laravel deployments by skipping asset compilation.

Building a Custom Trigger

Hammerstone Refine has not launched yet. Sign up for the early access list to stay up to date!

If the File and Config triggers don't meet your needs, you are free to make your own.

Let's imagine we want to trigger an asset rebuild any time the week of the year changes. This will force assets to be built at least once a week, provided we deploy at least once a week.

Creating the Class

Your custom trigger class must implement the Hammerstone TriggerContract.

WeekTrigger.php

1use Hammerstone\Airdrop\Contracts\TriggerContract;
2 
3class WeekTrigger implements TriggerContract
4{
5 /**
6 * Return any state that should be considered when determining
7 * whether or not your build process needs to run again.
8 *
9 * @param array $config
10 * @return array
11 */
12 public function triggerBuildWhenChanged($config = [])
13 {
14 // @TODO
15 }
16}

With that contract, you'll be forced to implement a method triggerBuildWhenChanged. This method will receive the config for this particular trigger, if there is any.

In our case, we just want to return the week of the year, so we'll ignore that config.

WeekTrigger.php

1use Hammerstone\Airdrop\Contracts\TriggerContract;
2 
3class WeekTrigger implements TriggerContract
4{
5 /**
6 * Return any state that should be considered when determining
7 * whether or not your build process needs to run again.
8 *
9 * @param array $config
10 * @return array
11 */
12 public function triggerBuildWhenChanged($config = [])
13 {
14 return now()->weekOfYear;
15 }
16}
Code highlighting powered by torchlight.dev, a Hammerstone product.

Enabling Your Custom Trigger

To enable your trigger, you'll need to add it to airdrop.php. Since no config is required in this example you don't need to pass an empty array, you can just use the class name.

config/airdrop.php

1'triggers' => [
2 ConfigTrigger::class => [
3 // ...
4 ],
5 
6 FileTrigger::class => [
7 // ...
8 ],
9 
10 // Our custom trigger, no config required.
11 WeekTrigger::class,
12],

If you wanted to have configuration for your custom trigger, you could do so by setting the key to the class and the value to an array:

config/airdrop.php

1'triggers' => [
2 ConfigTrigger::class => [
3 // ...
4 ],
5 
6 FileTrigger::class => [
7 // ...
8 ],
9 
10 // Our custom trigger, with some configuration
11 WeekTrigger::class => [
12 'key' => 'value'
13 ],
14],