-
Notifications
You must be signed in to change notification settings - Fork 3
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
Showing
7 changed files
with
277 additions
and
2 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,33 @@ | ||
# vendor-versions | ||
Tracy panel with installed libraries version | ||
# Vendor Versions | ||
Vendor Versions is a bar panel for [Tracy](https://tracy.nette.org/) debugger. It loads `composer.lock` file and shows you versions of all currently installed libraries. | ||
|
||
|
||
# Installation | ||
Use [Composer](https://getcomposer.org) and require `milo/vendor-versions` package. | ||
|
||
If you are using Nette DI container, register panel in `config.neon`: | ||
```yaml | ||
extensions: | ||
vendorVersions: Milo\VendorVersions\Bridges\Nette\DI\Extension(%debugMode%) | ||
|
||
# Optionally set path do directory with composer.lock file | ||
vendorVersions: | ||
dir: 'some/path' | ||
``` | ||
|
||
If you are not using Nette DI, register panel manually: | ||
```php | ||
Tracy\Debugger::getBar()->addPanel( | ||
new Milo\VendorVersions\Panel | ||
); | ||
|
||
|
||
# Optionally with a path to directory with composer.lock file | ||
Tracy\Debugger::getBar()->addPanel( | ||
new Milo\VendorVersions\Panel(__DIR__ . '/some/dir') | ||
); | ||
``` | ||
|
||
|
||
# Screenshot | ||
![Tracy panel screenshot](https://github.com/milo/vendor-versions/raw/master/screenshot.png) |
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,26 @@ | ||
{ | ||
"name": "milo/vendor-versions", | ||
"type": "library", | ||
"description": "Bar with versions list of vendor libraries for Tracy", | ||
"keywords": ["tracy", "bar", "vendor", "composer", "composer.lock"], | ||
"license": ["MIT"], | ||
"authors": [ | ||
{ | ||
"name": "Miloslav Hůla", | ||
"email": "[email protected]", | ||
"homepage": "https://github.com/milo" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.4.0", | ||
"tracy/tracy": "^2.3.0" | ||
}, | ||
"suggest": { | ||
"nette/di": "For automatic panel loading" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Milo\\VendorVersions\\": "src/" | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,45 @@ | ||
<?php | ||
|
||
namespace Milo\VendorVersions\Bridges\Nette\DI; | ||
|
||
use Nette; | ||
|
||
/** | ||
* Nette DI extension. | ||
* | ||
* @licence MIT | ||
* @link https://github.com/milo/vendor-versions | ||
*/ | ||
class Extension extends Nette\DI\CompilerExtension | ||
{ | ||
private $defaults = [ | ||
'dir' => NULL, | ||
]; | ||
|
||
/** @var bool */ | ||
private $debugMode; | ||
|
||
|
||
/** | ||
* @param bool $debugMode | ||
*/ | ||
public function __construct($debugMode) | ||
{ | ||
$this->debugMode = $debugMode; | ||
} | ||
|
||
|
||
public function loadConfiguration() | ||
{ | ||
if ($this->debugMode) { | ||
$config = $this->getConfig() + $this->defaults; | ||
|
||
$container = $this->getContainerBuilder(); | ||
$container->getDefinition('tracy.bar') | ||
->addSetup('addPanel', [ | ||
new Nette\DI\Statement('Milo\VendorVersions\Panel', [$config['dir']]) | ||
]); | ||
} | ||
} | ||
|
||
} |
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,106 @@ | ||
<?php | ||
|
||
namespace Milo\VendorVersions; | ||
|
||
use Tracy; | ||
|
||
/** | ||
* Bar panel for Tracy (https://tracy.nette.org/) shows versions of libraries parsed from composer.lock. | ||
* | ||
* @licence MIT | ||
* @link https://github.com/milo/vendor-versions | ||
*/ | ||
class Panel implements Tracy\IBarPanel | ||
{ | ||
/** @var string */ | ||
private $error; | ||
|
||
/** @var string */ | ||
private $dir; | ||
|
||
|
||
/** | ||
* @param string $composerLockDir path to composer.lock's directory | ||
*/ | ||
public function __construct($composerLockDir = NULL) | ||
{ | ||
$composerLockDir = $composerLockDir ?: __DIR__ . '/../../../../'; | ||
if (!is_dir($dir = @realpath($composerLockDir))) { | ||
$this->error = "Path '$composerLockDir' is not a directory."; | ||
} elseif (!is_file($dir . DIRECTORY_SEPARATOR . 'composer.lock')) { | ||
$this->error = "Directory '$dir' does not contain the composer.lock file."; | ||
} else { | ||
$this->dir = $dir; | ||
} | ||
} | ||
|
||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getTab() | ||
{ | ||
ob_start(); | ||
require __DIR__ . '/templates/Panel.tab.phtml'; | ||
return ob_get_clean(); | ||
} | ||
|
||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getPanel() | ||
{ | ||
ob_start(); | ||
|
||
if ($this->error === NULL) { | ||
$file = $this->dir . DIRECTORY_SEPARATOR . 'composer.lock'; | ||
$json = @file_get_contents($file); | ||
if ($json === FALSE) { | ||
$this->error = error_get_last()['message']; | ||
return NULL; | ||
} | ||
|
||
$decoded = @json_decode($json, TRUE); | ||
if (!is_array($decoded)) { | ||
$this->error = error_get_last()['message']; | ||
return NULL; | ||
} | ||
|
||
$data = [ | ||
'Packages' => self::format($decoded['packages']), | ||
'Dev Packages' => self::format($decoded['packages-dev']), | ||
]; | ||
} | ||
|
||
$error = $this->error; | ||
|
||
require __DIR__ . '/templates/Panel.panel.phtml'; | ||
return ob_get_clean(); | ||
} | ||
|
||
|
||
/** | ||
* @param array $packages | ||
* @return array | ||
*/ | ||
private static function format(array $packages) | ||
{ | ||
$data = []; | ||
foreach ($packages as $p) { | ||
$data[$p['name']] = (object) [ | ||
'version' => $p['version'] . ($p['version'] === 'dev-master' | ||
? (' #' . substr($p['source']['reference'], 0, 7)) | ||
: '' | ||
), | ||
'url' => isset($p['source']['url']) | ||
? preg_replace('/\.git$/', '', $p['source']['url']) | ||
: NULL, | ||
]; | ||
} | ||
|
||
ksort($data); | ||
return $data; | ||
} | ||
|
||
} |
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,64 @@ | ||
<?php | ||
|
||
namespace Milo\VendorVersions\Panel; | ||
|
||
use Tracy\Helpers; | ||
|
||
function h($str) { | ||
return htmlSpecialChars($str, ENT_QUOTES | ENT_HTML5, 'UTF-8'); | ||
} | ||
|
||
/** | ||
* @var string|NULL $file | ||
* @var string|NULL $error | ||
* @var array $data | ||
*/ | ||
?> | ||
<style class="tracy-debug"> | ||
.milo-VendorVersionsPanel h2 { | ||
font-weight: bold !important; | ||
} | ||
|
||
.milo-VendorVersionsPanel small { | ||
font-size: 85% !important; | ||
} | ||
|
||
.milo-VendorVersionsPanel .tracy-inner { | ||
width: 350px; | ||
} | ||
|
||
.milo-VendorVersionsPanel table { | ||
white-space: nowrap; | ||
font: 9pt/1.5 Consolas,monospace !important; | ||
} | ||
</style> | ||
|
||
<div class="milo-VendorVersionsPanel"> | ||
<h1>Vendor Versions</h1> | ||
<div class="tracy-inner"> | ||
<?php if ($error): ?> | ||
<span style="color:red"><?= h($error) ?></span> | ||
<?php else: ?> | ||
<?php foreach ($data as $title => $packages): ?> | ||
<h2><?= h($title) ?></h2> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Name</th> | ||
<th>Version</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<?php foreach ($packages as $name => $p): ?> | ||
<tr> | ||
<td><?= $p->url ? ("<a href='" . h($p->url) . "' target='_blank' rel='noreferrer'>" . h($name) . "</a>") : h($name) ?></td> | ||
<td><?= h($p->version) ?></td> | ||
</tr> | ||
<?php endforeach ?> | ||
</tbody> | ||
</table> | ||
<?php endforeach ?> | ||
<p><small>Source: <?= Helpers::editorLink($file) ?></small></p> | ||
<?php endif ?> | ||
</div> | ||
</div> |
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,3 @@ | ||
<span title="Vendor Versions"> | ||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 600 512"><path fill="#478CCC" d="M489.349,131.258l0.47-0.462L374.228,15.515l-32.895,32.894l65.485,65.47c-29.182,11.174-49.97,39.258-49.97,72.303 c0,42.818,34.758,77.576,77.575,77.576c11.016,0,21.576-2.326,31.03-6.516V480.97c0,17.061-13.97,31.03-31.03,31.03 s-31.03-13.97-31.03-31.03V341.333c0-34.287-27.772-62.061-62.061-62.061h-31.03V62.061C310.303,27.772,282.53,0,248.242,0H62.061 C27.772,0,0,27.772,0,62.061v496.485h310.303V325.818h46.546V480.97c0,42.818,34.758,77.576,77.575,77.576 c42.818,0,77.576-34.758,77.576-77.576V186.182C512,164.772,503.303,145.379,489.349,131.258z M248.242,217.212H62.061V62.061 h186.182V217.212z M434.424,217.212c-17.061,0-31.03-13.962-31.03-31.03s13.97-31.03,31.03-31.03s31.03,13.962,31.03,31.03 S451.484,217.212,434.424,217.212z"/></svg> | ||
</span> |