Skip to content

Commit 8110e1f

Browse files
authored
Merge pull request #4782 from Laravel-Backpack/update-command
add `backpack:publish-assets` command that publishes CSS and JS assets
2 parents 100b3f3 + 8e1f8c2 commit 8110e1f

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

src/BackpackServiceProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class BackpackServiceProvider extends ServiceProvider
1717
\Backpack\CRUD\app\Console\Commands\Install::class,
1818
\Backpack\CRUD\app\Console\Commands\AddSidebarContent::class,
1919
\Backpack\CRUD\app\Console\Commands\AddCustomRouteContent::class,
20+
\Backpack\CRUD\app\Console\Commands\PublishAssets::class,
2021
\Backpack\CRUD\app\Console\Commands\Version::class,
2122
\Backpack\CRUD\app\Console\Commands\CreateUser::class,
2223
\Backpack\CRUD\app\Console\Commands\PublishBackpackMiddleware::class,
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace Backpack\CRUD\app\Console\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use Symfony\Component\Process\Exception\ProcessFailedException;
7+
use Symfony\Component\Process\Process;
8+
9+
class PublishAssets extends Command
10+
{
11+
/**
12+
* The name and signature of the console command.
13+
*
14+
* @var string
15+
*/
16+
protected $signature = 'backpack:publish-assets';
17+
18+
/**
19+
* The console command description.
20+
*
21+
* @var string
22+
*/
23+
protected $description = 'Publish new CSS and JS assets (will override existing ones).';
24+
25+
/**
26+
* Execute the console command.
27+
*
28+
* @return mixed
29+
*/
30+
public function handle()
31+
{
32+
$this->runConsoleCommand(['php', 'artisan', 'vendor:publish', '--provider=Backpack\CRUD\BackpackServiceProvider', '--tag=public', '--force']);
33+
}
34+
35+
/**
36+
* Run a shell command in a separate process.
37+
*
38+
* @param string $command Text to be executed.
39+
* @return void
40+
*/
41+
private function runConsoleCommand($command)
42+
{
43+
$process = new Process($command, null, null, null, 60, null);
44+
$process->run(function ($type, $buffer) {
45+
$this->line($buffer);
46+
});
47+
48+
// executes after the command finishes
49+
if (! $process->isSuccessful()) {
50+
throw new ProcessFailedException($process);
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)