Skip to content

Commit 9bbf55b

Browse files
authored
Add command to invalidate asset cache (#190)
1 parent 04271d8 commit 9bbf55b

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Laravel\VaporCli\Commands;
4+
5+
use Laravel\VaporCli\Helpers;
6+
use Laravel\VaporCli\Manifest;
7+
use Symfony\Component\Console\Input\InputArgument;
8+
9+
class InvalidateAssetCacheCommand extends Command
10+
{
11+
/**
12+
* Configure the command options.
13+
*
14+
* @return void
15+
*/
16+
protected function configure()
17+
{
18+
$this
19+
->setName('asset:invalidate-cache')
20+
->addArgument('environment', InputArgument::OPTIONAL, 'The environment name')
21+
->setDescription('Invalidate the asset cache for the given environment');
22+
}
23+
24+
/**
25+
* Execute the command.
26+
*
27+
* @return void
28+
*/
29+
public function handle()
30+
{
31+
Helpers::ensure_api_token_is_available();
32+
33+
$this->vapor->invalidateAssetCache(
34+
Manifest::id(),
35+
$this->argument('environment')
36+
);
37+
38+
Helpers::info("Asset cache for {$this->argument('environment')} is being invalidated.");
39+
}
40+
}

src/ConsoleVaporClient.php

+11
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,17 @@ public function recordArtifactAssets($artifactId, array $files)
10741074
]);
10751075
}
10761076

1077+
/**
1078+
* Invalidate the asset cache for the given environment.
1079+
*
1080+
* @param string $environment
1081+
* @return array
1082+
*/
1083+
public function invalidateAssetCache($projectId, $environment)
1084+
{
1085+
return $this->requestWithErrorHandling('post', '/api/projects/'.$projectId.'/environments/'.$environment.'/invalidate-assets');
1086+
}
1087+
10771088
/**
10781089
* Get all of the deployments for the given project.
10791090
*

vapor

+4-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ if (file_exists(__DIR__.'/../../autoload.php')) {
2626
*/
2727
(function () {
2828
if (class_exists(RepositoryBuilder::class)) {
29-
3029
$adapters = [
3130
V4orV5EnvConstAdapter::class,
3231
V4orV5ServerConstAdapter::class,
@@ -56,7 +55,7 @@ if (file_exists(__DIR__.'/../../autoload.php')) {
5655
)->safeLoad();
5756
} else { // V3
5857
Dotenv::create(__DIR__, null, new DotenvFactory([
59-
new V3EnvConstAdapter, new V3ServerConstAdapter
58+
new V3EnvConstAdapter, new V3ServerConstAdapter,
6059
]))->safeLoad();
6160
}
6261
})();
@@ -206,4 +205,7 @@ $app->add(new Commands\MetricsCommand);
206205
$app->add(new Commands\LocalCommand);
207206
$app->add(new Commands\TestCommand);
208207

208+
// Assets...
209+
$app->add(new Commands\InvalidateAssetCacheCommand);
210+
209211
$app->run();

0 commit comments

Comments
 (0)