37 lines
1.4 KiB
PHP
37 lines
1.4 KiB
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Support\Architecture\DependencyMapGenerator;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
final class DependencyMapCommand extends Command
|
|
{
|
|
protected $signature = 'app:dependency-map {--markdown : Also write docs/architecture/dependency-map.md}';
|
|
protected $description = 'Generate a module dependency map for governance review.';
|
|
|
|
public function handle(DependencyMapGenerator $generator): int
|
|
{
|
|
$map = $generator->generate();
|
|
Storage::disk('local')->put('generated/dependency-map.json', json_encode($map, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
|
|
|
if ($this->option('markdown')) {
|
|
$lines = ['# Dependency Map', '', 'Generated from PHP imports. Treat this as a smoke alarm, not a philosophical essay.', ''];
|
|
foreach ($map['files'] as $file => $imports) {
|
|
$lines[] = '## `'.$file.'`';
|
|
$lines[] = '';
|
|
foreach ($imports as $import) {
|
|
$lines[] = '- `'.$import.'`';
|
|
}
|
|
$lines[] = '';
|
|
}
|
|
@mkdir(base_path('docs/architecture'), 0777, true);
|
|
file_put_contents(base_path('docs/architecture/dependency-map.md'), implode(PHP_EOL, $lines).PHP_EOL);
|
|
}
|
|
|
|
$this->info('Dependency map generated. Now the imports have fewer places to hide.');
|
|
return self::SUCCESS;
|
|
}
|
|
}
|