-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1074f8c
commit ed8e98f
Showing
3 changed files
with
140 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use System\Console\Command; | ||
use System\Console\Style\ProgressBar; | ||
|
||
use function System\Console\fail; | ||
use function System\Console\ok; | ||
use function System\Console\style; | ||
use function System\Console\warn; | ||
|
||
require_once __DIR__ . '../../vendor/autoload.php'; | ||
|
||
$command = new class($argv) extends Command { | ||
public function entry(): int | ||
{ | ||
return match (true) { | ||
'validate' === $this->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<string, string|array<string, string>> | ||
*/ | ||
private function loadConfig(): array | ||
{ | ||
return require __DIR__ . '../../split-repo.php'; | ||
} | ||
|
||
/** | ||
* Load composer as array. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
private function loadComposer(string $path): array | ||
{ | ||
$composer_file = file_get_contents($path); | ||
|
||
return json_decode($composer_file, true); | ||
} | ||
}; | ||
|
||
exit($command->entry()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
return [ | ||
'tag_version' => "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/', | ||
], | ||
]; |