Skip to content

Instantly share code, notes, and snippets.

@gquemener
Created March 19, 2018 09:26
Show Gist options
  • Save gquemener/77c8e4da2549f62aada2cf61101a911d to your computer and use it in GitHub Desktop.
Save gquemener/77c8e4da2549f62aada2cf61101a911d to your computer and use it in GitHub Desktop.
<?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