diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index fa76f3fc..89cbd7fc 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -4,7 +4,7 @@ ->in(__DIR__ . DIRECTORY_SEPARATOR . 'tests') ->in(__DIR__ . DIRECTORY_SEPARATOR . 'src') ->exclude(__DIR__ . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'Template') - ->append(['.php-cs-fixer.php', 'monorepo-builder.php', 'rector.php']); + ->append(['.php-cs-fixer.php', 'monorepo-builder.php', 'rector.php', './bin/split-repo.php']); $rules = [ '@Symfony' => true, diff --git a/bin/split-repo.php b/bin/split-repo.php new file mode 100644 index 00000000..e88e7ab8 --- /dev/null +++ b/bin/split-repo.php @@ -0,0 +1,115 @@ +CMD => $this->validate(), + default => 0, + }; + } + + public function validate(): int + { + $config = $this->loadConfig(); + $version = $config['tag_version']; + $split_repositorys = $config['split_repositorys']; + $paths = array_values($split_repositorys); + $packages = array_keys($split_repositorys); + $progressbar = new ProgressBar(); + $progressbar->complete = static fn (): string => (string) ok('Done, your monorepo is greate!!!'); + $progressbar->maks = count($paths); + + foreach ($paths as $path) { + if (false === $this->validateComposerVersion($composer_path = dirname(__DIR__) . $path . 'composer.json', $packages, $version)) { + $progressbar->complete = static fn (): string => (string) fail('failed!'); + $progressbar->current = $progressbar->maks + 1; + $progressbar->tick(); + + warn('Conflig found')->out(false); + + if (file_exists($composer_path)) { + style('your version: ')->push($version)->textDim()->out(); + $composer = $this->loadComposer($composer_path); + foreach ($composer['require'] as $package => $package_version) { + if (in_array($package, $packages)) { + style($package)->textYellow()->push(':')->push($package_version)->textDim()->out(); + } + } + } + + return 1; + } + + $progressbar->current++; + $progressbar->tick(); + } + + return 0; + } + + /** + * Validate Composer pacakge version by compire with current verstion. + * + * @param string[] $packages + */ + private function validateComposerVersion(string $path, array $packages, string $version): bool + { + if (false === file_exists($path)) { + return true; + } + + $composer = $this->loadComposer($path); + + if (false === array_key_exists('require', $composer)) { + return true; + } + + foreach ($composer['require'] as $package => $package_version) { + $package_version = preg_replace('/[^\d\.]/', '', $package_version); + if (in_array($package, $packages)) { + if ($package_version !== $version) { + return false; + } + } + } + + return true; + } + + /** + * Load split configuration. + * + * @return array> + */ + private function loadConfig(): array + { + return require __DIR__ . '../../split-repo.php'; + } + + /** + * Load composer as array. + * + * @return array + */ + private function loadComposer(string $path): array + { + $composer_file = file_get_contents($path); + + return json_decode($composer_file, true); + } +}; + +exit($command->entry()); diff --git a/composer.json b/composer.json index db2a93a0..a7747f94 100644 --- a/composer.json +++ b/composer.json @@ -48,20 +48,20 @@ ] }, "replace": { - "sonypradana/collection": "0.35.6", - "sonypradana/console": "0.35.6", - "sonypradana/container": "0.35.6", - "sonypradana/cron": "0.35.6", - "sonypradana/database": "0.35.6", - "sonypradana/file": "0.35.6", - "sonypradana/http": "0.35.6", - "sonypradana/router": "0.35.6", - "sonypradana/security": "0.35.6", - "sonypradana/support": "0.35.6", - "sonypradana/template": "0.35.6", - "sonypradana/text": "0.35.6", - "sonypradana/time": "0.35.6", - "sonypradana/view": "0.35.6" + "sonypradana/collection": "self.version", + "sonypradana/console": "self.version", + "sonypradana/container": "self.version", + "sonypradana/cron": "self.version", + "sonypradana/database": "self.version", + "sonypradana/file": "self.version", + "sonypradana/http": "self.version", + "sonypradana/router": "self.version", + "sonypradana/security": "self.version", + "sonypradana/support": "self.version", + "sonypradana/template": "self.version", + "sonypradana/text": "self.version", + "sonypradana/time": "self.version", + "sonypradana/view": "self.version" }, "extra": { "branch-alias": { @@ -75,17 +75,20 @@ "test:lint": "php-cs-fixer fix -v --dry-run --diff", "test:types": "phpstan analyse --ansi --memory-limit=-1 --debug", "test:unit": "phpunit --testdox --exclude-group database", + "test:release": "php .\\bin\\split-repo.php validate", "test:dev": [ "@test:refacto", "@test:lint", "@test:types", - "@test:unit" + "@test:unit", + "@test:release" ], "test": [ "rector --dry-run", "php-cs-fixer fix -v --dry-run", "phpstan analyse --ansi --memory-limit=-1", - "phpunit --exclude-group database" + "phpunit --exclude-group database", + "php .\\bin\\split-repo.php validate" ] }, "minimum-stability": "dev", diff --git a/split-repo.php b/split-repo.php new file mode 100644 index 00000000..ec9b48fc --- /dev/null +++ b/split-repo.php @@ -0,0 +1,24 @@ + "0.35.6", + 'split_repositorys' => [ + 'sonypradana/collection' => '/src/System/Collection/', + 'sonypradana/console' => '/src/System/Console/', + 'sonypradana/container' => '/src/System/Container/', + 'sonypradana/cron' => '/src/System/Cron/', + 'sonypradana/database' => '/src/System/Database/', + 'sonypradana/file' => '/src/System/File/', + 'sonypradana/http' => '/src/System/Http/', + 'sonypradana/macroable' => '/src/System/Macroable/', + 'sonypradana/router' => '/src/System/Router/', + 'sonypradana/security' => '/src/System/Security/', + 'sonypradana/support' => '/src/System/Support/', + 'sonypradana/template' => '/src/System/Template/', + 'sonypradana/text' => '/src/System/Text/', + 'sonypradana/time' => '/src/System/Time/', + 'sonypradana/view' => '/src/System/View/', + ], +];