This commit is contained in:
Maxime 2024-04-08 01:14:31 +02:00
commit e8c48a7fdb
9 changed files with 229 additions and 0 deletions

15
.editorconfig Normal file
View File

@ -0,0 +1,15 @@
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false
[*.{yml,yaml}]
indent_size = 2

7
.gitattributes vendored Normal file
View File

@ -0,0 +1,7 @@
* text=auto
*.php diff=php
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
/vendor
composer.lock
/.idea

31
README.md Normal file
View File

@ -0,0 +1,31 @@
# BAG Laravel Helper
This package provides Laravel commands to execute BAG for Laravel Stack.
## Installation
Edit your `composer.json` file to include the following dependency:
```
"require": {
"bag/laravel-helper": "dev-main"
},
"repositories": [
{
"type": "vcs",
"url": "git@git.bluesquare.io:bag/laravel-helper.git"
}
]
```
Then run:
```bash
composer update bag/laravel-helper
```
## Usage
```
php artisan bag:migrations
```

32
composer.json Normal file
View File

@ -0,0 +1,32 @@
{
"name": "bag/laravel-helper",
"description": "Add BAG features to your Laravel project.",
"keywords": ["laravel", "bag"],
"license": "MIT",
"authors": [
{
"name": "Maxime Renou",
"email": "maxime@bluesquare.io"
}
],
"require": {
"php": "^8.1.0"
},
"autoload": {
"psr-4": {
"BAG\\Laravel\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"BAG\\Laravel\\ServiceProvider"
]
}
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
}

2
packages/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore

View 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();
}
}

View 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!");
}
}

47
src/ServiceProvider.php Normal file
View File

@ -0,0 +1,47 @@
<?php
namespace BAG\Laravel;
use Illuminate\Contracts\Support\DeferrableProvider;
class ServiceProvider extends \Illuminate\Support\ServiceProvider implements DeferrableProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
if (! $this->app->runningInConsole()) {
return;
}
$this->commands([
Console\MakeMigrations::class,
//...
]);
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return [
Console\MakeMigrations::class,
];
}
}