You've already forked laravel-helper
init
This commit is contained in:
27
src/Console/MakeMigrations.php
Normal file
27
src/Console/MakeMigrations.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace BAG\Laravel\Console;
|
||||
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
|
||||
#[AsCommand(name: 'bag:migrations')]
|
||||
class MakeMigrations extends ProxyCommand
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'bag:migrations';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Generate migrations based on current database schema and models';
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
public function proxyHandle()
|
||||
{
|
||||
return app(\BAG\Stack\Laravel\MakeMigrations::class)->run();
|
||||
}
|
||||
}
|
||||
65
src/Console/ProxyCommand.php
Normal file
65
src/Console/ProxyCommand.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace BAG\Laravel\Console;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Process;
|
||||
|
||||
abstract class ProxyCommand extends Command
|
||||
{
|
||||
protected $base_path;
|
||||
|
||||
abstract protected function proxyHandle();
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$this->base_path = realpath(__DIR__ . '/../..');
|
||||
|
||||
try {
|
||||
$this->syncPackages();
|
||||
return $this->proxyHandle();
|
||||
}
|
||||
catch (\Exception $exception) {
|
||||
$this->error($exception->getMessage());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
protected function syncPackages(): void
|
||||
{
|
||||
$this->syncPackage('stack-laravel');
|
||||
}
|
||||
|
||||
protected function syncPackage($package): void
|
||||
{
|
||||
$install_path = "{$this->base_path}/packages";
|
||||
$package_path = "$install_path/$package";
|
||||
|
||||
if (! is_dir($package_path)) {
|
||||
$this->info("🚚 Installing bag/$package...");
|
||||
|
||||
$result = Process::path($install_path)
|
||||
->run("git clone git@git.bluesquare.io:bag/$package.git $package");
|
||||
|
||||
if ($result->failed()) {
|
||||
throw new \Exception("Failed to fetch bag/$package");
|
||||
}
|
||||
} elseif (! cache()->has("bag/$package")) {
|
||||
$this->info("🤖 Updating bag/$package...");
|
||||
$result = Process::path($package_path)->run("git pull");
|
||||
|
||||
if ($result->failed()) {
|
||||
$this->warn("😰 Failed to update!");
|
||||
}
|
||||
|
||||
cache()->put("bag/$package", true, now()->addMinutes(5));
|
||||
}
|
||||
|
||||
$this->info("🐠 Loading bag/$package...");
|
||||
$result = Process::path($package_path)->run("composer install --ignore-platform-reqs");
|
||||
|
||||
require_once $package_path.'/vendor/autoload.php';
|
||||
|
||||
$this->info("⚡️ Ready!");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user