diff --git a/src/Commands/Seat/DevEnv/BuildDevEnv.php b/src/Commands/Seat/DevEnv/BuildDevEnv.php new file mode 100644 index 00000000..a52c2438 --- /dev/null +++ b/src/Commands/Seat/DevEnv/BuildDevEnv.php @@ -0,0 +1,67 @@ +parse_json_file($this->option('composer_json')); + $override = $this->parse_json_file($this->option('override_json')); + + if($composer === null || $override === null) return; + + $composer_repos = $override['repositories'] ?? []; + $composer['repositories'] = array_map(function ($repo){ + return [ + 'type'=>'path', + 'url'=>$repo['path'], + 'options'=>[ + 'symlink'=>true, + 'versions'=>[ + $repo['package']=>$repo['as_version'] + ] + ] + ]; + }, $composer_repos); + + $new_composer = json_encode($composer,JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); + $this->info($new_composer); + file_put_contents($this->option('composer_json'), $new_composer); + } + + private function parse_json_file($path) : mixed + { + $content = file_get_contents($path); + if($content === false){ + $this->error(sprintf('Failed to open \'%s\'.', $path)); + return null; + } + + $data = json_decode($content, JSON_OBJECT_AS_ARRAY); + if($data === null){ + $this->error(sprintf('Failed to parse json in \'%s\'.', $path)); + return null; + } + + return $data; + } +} \ No newline at end of file diff --git a/src/ServicesServiceProvider.php b/src/ServicesServiceProvider.php index 4e9746f8..1009899e 100644 --- a/src/ServicesServiceProvider.php +++ b/src/ServicesServiceProvider.php @@ -24,6 +24,7 @@ use Illuminate\Support\Facades\DB; use Seat\Services\Commands\Seat\Admin\Email; +use Seat\Services\Commands\Seat\DevEnv\BuildDevEnv; use Seat\Services\Commands\Seat\Version; class ServicesServiceProvider extends AbstractSeatPlugin @@ -94,6 +95,7 @@ private function addCommands() $this->commands([ Email::class, Version::class, + BuildDevEnv::class, ]); }