-
Notifications
You must be signed in to change notification settings - Fork 893
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 #5552 from Laravel-Backpack/save-to-mobile-without…
…-address-bar Add header metas publish command
- Loading branch information
Showing
17 changed files
with
202 additions
and
14 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
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,109 @@ | ||
<?php | ||
|
||
namespace Backpack\CRUD\app\Console\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\File; | ||
use Illuminate\Support\Str; | ||
|
||
class PublishHeaderMetas extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'backpack:publish-header-metas'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Publishes the header metas and favicon assets.'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() | ||
{ | ||
$appName = $this->ask('What is the application name ?', config('app.name').' Backoffice'); | ||
$backpackPrefix = config('backpack.base.route_prefix'); | ||
$appColor = $this->ask('What is the application color ?', '#161c2d'); | ||
$pathPrefix = $this->ask('Where should icon files be published relative to public folder?'); | ||
|
||
$pathPrefix = Str::finish($pathPrefix ?? '', '/'); | ||
|
||
// laravel adds a dummy favicon with 0 bytes. we need to remove it otherwise our script would skip publishing the favicon on new Laravel installations. | ||
// we will check the favicon file size, to make sure it's not a "valid" favicon. we will only delete the favicon if it has 0 bytes in size. | ||
$this->checkIfFaviconIsLaravelDefault($pathPrefix); | ||
|
||
$stubPath = __DIR__.'/../../../resources/stubs/'; | ||
|
||
$filesToPublish = [ | ||
public_path($pathPrefix.'site.webmanifest') => $stubPath.'manifest.stub', | ||
resource_path('views/vendor/backpack/ui/inc/header_metas.blade.php') => $stubPath.'header_metas.stub', | ||
public_path($pathPrefix.'browserconfig.xml') => $stubPath.'browserconfig.stub', | ||
public_path($pathPrefix.'android-chrome-192x192.png') => __DIR__.'/../../../public/android-chrome-192x192.png', | ||
public_path($pathPrefix.'android-chrome-192x192.png'), | ||
public_path($pathPrefix.'android-chrome-512x512.png'), | ||
public_path($pathPrefix.'apple-touch-icon.png'), | ||
public_path($pathPrefix.'favicon-16x16.png'), | ||
public_path($pathPrefix.'favicon-32x32.png'), | ||
public_path($pathPrefix.'favicon.ico'), | ||
public_path($pathPrefix.'safari-pinned-tab.svg'), | ||
public_path($pathPrefix.'mstile-70x70.png'), | ||
public_path($pathPrefix.'mstile-144x144.png'), | ||
public_path($pathPrefix.'mstile-150x150.png'), | ||
public_path($pathPrefix.'mstile-310x150.png'), | ||
public_path($pathPrefix.'mstile-310x310.png'), | ||
]; | ||
|
||
foreach ($filesToPublish as $destination => $stub) { | ||
if (! is_string($destination)) { | ||
$destination = $stub; | ||
$stub = null; | ||
} | ||
|
||
if (File::exists($destination)) { | ||
$this->comment("The file {$destination} already exists. Skipping."); | ||
|
||
continue; | ||
} | ||
|
||
if (! File::isDirectory(dirname($destination))) { | ||
File::makeDirectory(dirname($destination), 0755, true); | ||
} | ||
|
||
if (! $stub) { | ||
File::copy(__DIR__.'/../../../public/'.basename($destination), $destination); | ||
$this->info("File {$destination} published."); | ||
continue; | ||
} | ||
|
||
$stub = File::get($stub); | ||
|
||
$stub = str_replace('__APP_NAME__', $appName, $stub); | ||
$stub = str_replace('__APP_COLOR__', $appColor, $stub); | ||
$stub = str_replace('__BACKPACK_PREFIX__', $backpackPrefix, $stub); | ||
$stub = str_replace('__PATH_PREFIX__', $pathPrefix, $stub); | ||
|
||
File::put($destination, $stub); | ||
|
||
$this->info("File {$destination} published."); | ||
} | ||
|
||
$this->comment('[DONE] Metas and favicon assets published successfully.'); | ||
} | ||
|
||
private function checkIfFaviconIsLaravelDefault(string $path) | ||
{ | ||
if (File::exists(public_path($path.'favicon.ico'))) { | ||
// check the file size. if it's 0 it's the laravel dummy favicon, remove it. | ||
if (filesize(public_path($path.'favicon.ico')) === 0) { | ||
File::delete(public_path($path.'favicon.ico')); | ||
$this->comment('[INFO] We deleted the Laravel dummy favicon. Publishing assets now.'); | ||
} | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<browserconfig> | ||
<msapplication> | ||
<tile> | ||
<square150x150logo src="__PATH_PREFIX__mstile-150x150.png"/> | ||
<TileColor>__APP_COLOR__</TileColor> | ||
</tile> | ||
</msapplication> | ||
</browserconfig> |
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,13 @@ | ||
<meta name="apple-mobile-web-app-capable" content="yes" /> | ||
<meta name="mobile-web-app-capable" content="yes" /> | ||
<link rel="apple-touch-icon" sizes="180x180" href="{{ asset('__PATH_PREFIX__apple-touch-icon.png') }}"> | ||
<link rel="icon" type="image/png" href="{{ asset('__PATH_PREFIX__favicon-32x32.png') }}" sizes="32x32"> | ||
<link rel="icon" type="image/png" href="{{ asset('__PATH_PREFIX__favicon-16x16.png') }}" sizes="16x16"> | ||
<link rel="manifest" href="{{ asset('__PATH_PREFIX__site.webmanifest') }}"> | ||
<link rel="mask-icon" href="{{ asset('__PATH_PREFIX__safari-pinned-tab.svg') }}" color="__APP_COLOR__"> | ||
<link rel="shortcut icon" href="{{ asset('__PATH_PREFIX__favicon.ico') }}"> | ||
<meta name="theme-color" content="__APP_COLOR__"> | ||
<meta name="apple-mobile-web-app-title" content="__APP_NAME__"> | ||
<meta name="application-name" content="__APP_NAME__"> | ||
<meta name="msapplication-TileColor" content="__APP_COLOR__"> | ||
<meta name="msapplication-config" content="{{asset('__PATH_PREFIX__browserconfig.xml')}}"> |
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,19 @@ | ||
{ | ||
"name": "__APP_NAME__", | ||
"icons": [ | ||
{ | ||
"src": "__PATH_PREFIX__android-chrome-192x192.png", | ||
"sizes": "192x192", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "__PATH_PREFIX__android-chrome-512x512.png", | ||
"sizes": "512x512", | ||
"type": "image/png" | ||
} | ||
], | ||
"theme_color": "__APP_COLOR__", | ||
"background_color": "__APP_COLOR__", | ||
"start_url": "/__BACKPACK_PREFIX__", | ||
"display": "standalone" | ||
} |