commit e8c48a7fdb671a2778462e25fd87e96dabd833a8 Author: Maxime Renou Date: Mon Apr 8 01:14:31 2024 +0200 init diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..6537ca4 --- /dev/null +++ b/.editorconfig @@ -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 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..d83d3e5 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,7 @@ +* text=auto + +*.php diff=php + +.editorconfig export-ignore +.gitattributes export-ignore +.gitignore export-ignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e8f94b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/vendor +composer.lock +/.idea diff --git a/README.md b/README.md new file mode 100644 index 0000000..3f17366 --- /dev/null +++ b/README.md @@ -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 +``` diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..88cd2a0 --- /dev/null +++ b/composer.json @@ -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 +} diff --git a/packages/.gitignore b/packages/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/packages/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/src/Console/MakeMigrations.php b/src/Console/MakeMigrations.php new file mode 100644 index 0000000..9c5da36 --- /dev/null +++ b/src/Console/MakeMigrations.php @@ -0,0 +1,27 @@ +run(); + } +} diff --git a/src/Console/ProxyCommand.php b/src/Console/ProxyCommand.php new file mode 100644 index 0000000..d855194 --- /dev/null +++ b/src/Console/ProxyCommand.php @@ -0,0 +1,65 @@ +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!"); + } +} diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php new file mode 100644 index 0000000..af04a05 --- /dev/null +++ b/src/ServiceProvider.php @@ -0,0 +1,47 @@ +app->runningInConsole()) { + return; + } + + $this->commands([ + Console\MakeMigrations::class, + //... + ]); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return [ + Console\MakeMigrations::class, + ]; + } +}