Created
March 19, 2018 09:26
-
-
Save gquemener/77c8e4da2549f62aada2cf61101a911d to your computer and use it in GitHub Desktop.
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
<?php | |
$files = $argv; | |
unset($files[0]); | |
$packages = []; | |
foreach ($files as $file) { | |
$composer = json_decode(file_get_contents($file), true); | |
$requirements = $composer['require']; | |
$packages[$composer['name']] = array_keys($composer['require']); | |
} | |
$template = function($packages) { | |
$colors = ['red', 'green', 'blue', 'deeppink1', 'gold2', 'chartreuse']; | |
$result = ''; | |
$i = 0; | |
foreach ($packages as $name => $deps) { | |
$color = $colors[$i]; | |
$result .= sprintf("\n \"%s\" [color = %s]", $name, $color); | |
foreach ($deps as $dep) { | |
$result .= sprintf("\n \"%s\" -> \"%s\" [color = %s]", $name, $dep, $color); | |
} | |
++$i; | |
} | |
return $result; | |
}; | |
printf("digraph deps {\n rankdir=\"LR\"%s\n}", $template($packages)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment