glastree_on_gitea
This commit is contained in:
+28
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\LaravelPackageTools\Commands\Concerns;
|
||||
|
||||
trait AskToRunMigrations
|
||||
{
|
||||
protected bool $askToRunMigrations = false;
|
||||
|
||||
public function askToRunMigrations(): self
|
||||
{
|
||||
$this->askToRunMigrations = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function processAskToRunMigrations(): self
|
||||
{
|
||||
if ($this->askToRunMigrations) {
|
||||
if ($this->confirm('Would you like to run the migrations now?')) {
|
||||
$this->comment('Running migrations...');
|
||||
|
||||
$this->call('migrate');
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\LaravelPackageTools\Commands\Concerns;
|
||||
|
||||
trait AskToStarRepoOnGitHub
|
||||
{
|
||||
protected ?string $starRepo = null;
|
||||
|
||||
protected bool $defaultStarAnswer = true;
|
||||
|
||||
public function askToStarRepoOnGitHub($vendorSlashRepoName, bool $defaultAnswer = false): self
|
||||
{
|
||||
$this->starRepo = $vendorSlashRepoName;
|
||||
$this->defaultStarAnswer = $defaultAnswer;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function processStarRepo(): self
|
||||
{
|
||||
if ($this->starRepo) {
|
||||
if ($this->confirm('Would you like to star our repo on GitHub?', $this->defaultStarAnswer)) {
|
||||
$repoUrl = "https://github.com/{$this->starRepo}";
|
||||
|
||||
if (PHP_OS_FAMILY == 'Darwin') {
|
||||
exec("open {$repoUrl}");
|
||||
}
|
||||
if (PHP_OS_FAMILY == 'Windows') {
|
||||
exec("start {$repoUrl}");
|
||||
}
|
||||
if (PHP_OS_FAMILY == 'Linux') {
|
||||
exec("xdg-open {$repoUrl}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\LaravelPackageTools\Commands\Concerns;
|
||||
|
||||
trait PublishesResources
|
||||
{
|
||||
protected array $publishes = [];
|
||||
|
||||
public function publish(string ...$tag): self
|
||||
{
|
||||
$this->publishes = array_merge($this->publishes, $tag);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function publishAssets(): self
|
||||
{
|
||||
return $this->publish('assets');
|
||||
}
|
||||
|
||||
public function publishConfigFile(): self
|
||||
{
|
||||
return $this->publish('config');
|
||||
}
|
||||
|
||||
public function publishInertiaComponents(): self
|
||||
{
|
||||
return $this->publish('inertia-components');
|
||||
}
|
||||
|
||||
public function publishMigrations(): self
|
||||
{
|
||||
return $this->publish('migrations');
|
||||
}
|
||||
|
||||
protected function processPublishes(): self
|
||||
{
|
||||
foreach ($this->publishes as $tag) {
|
||||
$name = str_replace('-', ' ', $tag);
|
||||
$this->comment("Publishing {$name}...");
|
||||
|
||||
$this->callSilently("vendor:publish", [
|
||||
'--tag' => "{$this->package->shortName()}-{$tag}",
|
||||
]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\LaravelPackageTools\Commands\Concerns;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
trait SupportsServiceProviderInApp
|
||||
{
|
||||
protected bool $copyServiceProviderInApp = false;
|
||||
|
||||
public function copyAndRegisterServiceProviderInApp(): self
|
||||
{
|
||||
$this->copyServiceProviderInApp = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function processCopyServiceProviderInApp(): self
|
||||
{
|
||||
if ($this->copyServiceProviderInApp) {
|
||||
$this->comment('Publishing service provider...');
|
||||
|
||||
$this->copyServiceProviderInApp();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function copyServiceProviderInApp(): self
|
||||
{
|
||||
$providerName = $this->package->publishableProviderName;
|
||||
|
||||
if (! $providerName) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->callSilent('vendor:publish', ['--tag' => $this->package->shortName() . '-provider']);
|
||||
|
||||
$namespace = Str::replaceLast('\\', '', $this->laravel->getNamespace());
|
||||
|
||||
if (intval(app()->version()) < 11 || ! file_exists(base_path('bootstrap/providers.php'))) {
|
||||
$appConfig = file_get_contents(config_path('app.php'));
|
||||
} else {
|
||||
$appConfig = file_get_contents(base_path('bootstrap/providers.php'));
|
||||
}
|
||||
|
||||
$class = '\\Providers\\' . Str::replace('/', '\\', $providerName) . '::class';
|
||||
|
||||
if (Str::contains($appConfig, $namespace . $class)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (intval(app()->version()) < 11 || ! file_exists(base_path('bootstrap/providers.php'))) {
|
||||
file_put_contents(config_path('app.php'), str_replace(
|
||||
"{$namespace}\\Providers\\BroadcastServiceProvider::class,",
|
||||
"{$namespace}\\Providers\\BroadcastServiceProvider::class," . PHP_EOL . " {$namespace}{$class},",
|
||||
$appConfig
|
||||
));
|
||||
} else {
|
||||
file_put_contents(base_path('bootstrap/providers.php'), str_replace(
|
||||
"{$namespace}\\Providers\\AppServiceProvider::class,",
|
||||
"{$namespace}\\Providers\\AppServiceProvider::class," . PHP_EOL . " {$namespace}{$class},",
|
||||
$appConfig
|
||||
));
|
||||
}
|
||||
|
||||
file_put_contents(app_path('Providers/' . $providerName . '.php'), str_replace(
|
||||
"namespace App\Providers;",
|
||||
"namespace {$namespace}\Providers;",
|
||||
file_get_contents(app_path('Providers/' . $providerName . '.php'))
|
||||
));
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\LaravelPackageTools\Commands\Concerns;
|
||||
|
||||
use Closure;
|
||||
|
||||
trait SupportsStartWithEndWith
|
||||
{
|
||||
public ?Closure $startWith = null;
|
||||
public ?Closure $endWith = null;
|
||||
|
||||
public function startWith(callable $callable): self
|
||||
{
|
||||
$this->startWith = $callable;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function endWith(callable $callable): self
|
||||
{
|
||||
$this->endWith = $callable;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function processStartWith(): self
|
||||
{
|
||||
if ($this->startWith) {
|
||||
($this->startWith)($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function processEndWith(): self
|
||||
{
|
||||
if ($this->endWith) {
|
||||
($this->endWith)($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\LaravelPackageTools\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Spatie\LaravelPackageTools\Commands\Concerns\AskToRunMigrations;
|
||||
use Spatie\LaravelPackageTools\Commands\Concerns\AskToStarRepoOnGitHub;
|
||||
use Spatie\LaravelPackageTools\Commands\Concerns\PublishesResources;
|
||||
use Spatie\LaravelPackageTools\Commands\Concerns\SupportsServiceProviderInApp;
|
||||
use Spatie\LaravelPackageTools\Commands\Concerns\SupportsStartWithEndWith;
|
||||
use Spatie\LaravelPackageTools\Package;
|
||||
|
||||
class InstallCommand extends Command
|
||||
{
|
||||
use AskToRunMigrations;
|
||||
use AskToStarRepoOnGitHub;
|
||||
use PublishesResources;
|
||||
use SupportsServiceProviderInApp;
|
||||
use SupportsStartWithEndWith;
|
||||
|
||||
protected Package $package;
|
||||
|
||||
public function __construct(Package $package)
|
||||
{
|
||||
$this->signature = $package->shortName() . ':install';
|
||||
|
||||
$this->description = 'Install ' . $package->name;
|
||||
|
||||
$this->package = $package;
|
||||
|
||||
$this->hidden = true;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$this
|
||||
->processStartWith()
|
||||
->processPublishes()
|
||||
->processAskToRunMigrations()
|
||||
->processCopyServiceProviderInApp()
|
||||
->processStarRepo()
|
||||
->processEndWith();
|
||||
|
||||
$this->info("{$this->package->shortName()} has been installed!");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user