Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible updates & dev packages & caching & ... #4

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/vendor/
composer.lock
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ $configurator->onCompile[] = function ($config, Nette\Config\Compiler $compiler)

composerUpdates:
cacheDir: %tempDir%/cache
localConfigFile: %wwwDir%/../composer.json
rootDir: %wwwDir%/..
```

Screenshots
Expand Down
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
{
"name": "Matej Koubik",
"email": "[email protected]"
},
{
"name": "Jáchym Toušek",
"email": "[email protected]"
}
],
"license": ["BSD-2-Clause"],
Expand Down
8 changes: 4 additions & 4 deletions src/ComposerUpdates/DI/ComposerUpdatesExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ class ComposerUpdatesExtension extends Nette\DI\CompilerExtension
{
private $defaults = array(
'cacheDir' => NULL,
'localConfigFile' => NULL,
'rootDir' => NULL,
);

public function loadConfiguration()
{
$config = $this->getConfig($this->defaults);

if (!is_dir($config['cacheDir']) || !is_file($config['localConfigFile'])) {
if (!is_dir($config['cacheDir']) || !is_dir($config['rootDir'])) {
throw new \InvalidArgumentException("Please configure the ComposerUpdates extensions using the section '{$this->name}:' in your config file.");
}

$builder = $this->getContainerBuilder();

$builder->addDefinition($this->prefix('initializer'))
->setClass('ComposerUpdates\Initializer', array($config['cacheDir'], $config['localConfigFile']));
->setClass('ComposerUpdates\Initializer', array($config['cacheDir'], $config['rootDir']));

$builder->addDefinition($this->prefix('service'))
->setClass('ComposerUpdates\Service');

$builder->addDefinition($this->prefix('panel'))
->setClass('ComposerUpdates\Diagnostics\ComposerUpdatesPanel');
->setClass('ComposerUpdates\Diagnostics\ComposerUpdatesPanel', array($config['rootDir']));
}

public function afterCompile(Nette\PhpGenerator\ClassType $class)
Expand Down
43 changes: 30 additions & 13 deletions src/ComposerUpdates/Diagnostics/ComposerUpdatesPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,19 @@ class ComposerUpdatesPanel extends Nette\Object implements Nette\Diagnostics\IBa
/** @var ComposerUpdates\PackageInfo[] */
private $packages;

public function __construct(ComposerUpdates\Service $service)
public function __construct($rootDir, ComposerUpdates\Service $service, Nette\Caching\IStorage $storage)
{
$this->packages = $service->getPackages();
$cache = new Nette\Caching\Cache($storage, 'ComposerUpdates.panel');
$this->packages = $cache->load($rootDir, function (& $dependencies) use ($rootDir, $service) {
$dependencies = array(
Nette\Caching\Cache::EXPIRATION => '1 hour',
Nette\Caching\Cache::FILES => array(
$rootDir . '/composer.json',
$rootDir . '/composer.lock',
),
);
return array_merge($service->getPackages(), $service->getDevPackages());
});
}

/**
Expand All @@ -21,15 +31,21 @@ public function __construct(ComposerUpdates\Service $service)
*/
public function getTab()
{
if (empty($this->packages)) {
if (!$this->packages) {
return;
}

$updates = array_filter($this->packages, function(ComposerUpdates\PackageInfo $package) {
return $package->isUpdateAvailable();
});

$status = max(array_map(function(ComposerUpdates\PackageInfo $package) {
return $package->getStatus();
}, $this->packages));

$updates = count(array_filter($this->packages, function(ComposerUpdates\PackageInfo $package) {
$status = $package->getStatus();
return $status !== ComposerUpdates\PackageInfo::STATUS_NO_UPDATE && $status !== ComposerUpdates\PackageInfo::STATUS_NOT_INSTALLED;
}));

return self::render(__DIR__ . '/templates/tab.phtml', array(
'status' => $status,
'updates' => $updates,
));
}
Expand All @@ -40,18 +56,19 @@ public function getTab()
*/
public function getPanel()
{
if (empty($this->packages)) {
if (!$this->packages) {
return;
}

uasort($this->packages, function (ComposerUpdates\PackageInfo $package1, ComposerUpdates\PackageInfo $package2) {
$update1 = $package1->isUpdateAvailable();
$update2 = $package2->isUpdateAvailable();
return $update1 !== $update2 ? $update1 < $update2 : $package1->getName() > $package2->getName();
$packages = $this->packages;
uksort($packages, function ($key1, $key2) use ($packages) {
$status1 = $packages[$key1]->getStatus();
$status2 = $packages[$key2]->getStatus();
return $status1 !== $status2 ? $status1 < $status2 : $key1 > $key2;
});

return self::render(__DIR__ . '/templates/panel.phtml', array(
'packages' => $this->packages,
'packages' => $packages,
));
}

Expand Down
60 changes: 47 additions & 13 deletions src/ComposerUpdates/Diagnostics/templates/panel.phtml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<style>
#nette-debug .nette-composerUpdatesPanel .nette-inner {
width: 500px;
width: 700px;
}
#nette-debug .nette-composerUpdatesPanel table {
width: 100%;
Expand All @@ -13,50 +13,84 @@
vertical-align: middle;
margin-top: -2px;
}
#nette-debug .nette-composerUpdatesPanel .update-available,
#nette-debug .nette-composerUpdatesPanel .no-update {
#nette-debug .nette-composerUpdatesPanel .not-installed,
#nette-debug .nette-composerUpdatesPanel .no-update,
#nette-debug .nette-composerUpdatesPanel .incompatible-update,
#nette-debug .nette-composerUpdatesPanel .compatible-update {
display: inline-block;
width: 16px;
height: 16px;
border-radius: 8px;
margin-right: 3px;
}
#nette-debug .nette-composerUpdatesPanel .update-available {
background: #FFC029;
#nette-debug .nette-composerUpdatesPanel .not-installed {
background: #B1B1B1;
}
#nette-debug .nette-composerUpdatesPanel .no-update {
background: #599B4A;
}
#nette-debug .nette-composerUpdatesPanel .incompatible-update {
background: #FFC029;
}
#nette-debug .nette-composerUpdatesPanel .compatible-update {
background: #E60000;
}
#nette-debug .nette-composerUpdatesPanel abbr {
border-bottom: 1px dotted gray;
}
#nette-debug .nette-composerUpdatesPanel .notes {
margin-bottom: 10px;
}
</style>

<?php
$classes = array(
\ComposerUpdates\PackageInfo::STATUS_NOT_INSTALLED => 'not-installed',
\ComposerUpdates\PackageInfo::STATUS_NO_UPDATE => 'no-update',
\ComposerUpdates\PackageInfo::STATUS_INCOMPATIBLE_UPDATE => 'incompatible-update',
\ComposerUpdates\PackageInfo::STATUS_COMPATIBLE_UPDATE => 'compatible-update',
);
?>

<div class="nette-composerUpdatesPanel">
<h1>Composer updates</h1>
<div class="nette-inner">
<ul class="notes">
<li><span class="<?php echo $classes[\ComposerUpdates\PackageInfo::STATUS_NO_UPDATE] ?>"></span> There is no newer version of this library.</li>
<li><span class="<?php echo $classes[\ComposerUpdates\PackageInfo::STATUS_INCOMPATIBLE_UPDATE] ?>"></span> There is newer version but it may not be compatible with your project. Update with caution.</li>
<li><span class="<?php echo $classes[\ComposerUpdates\PackageInfo::STATUS_COMPATIBLE_UPDATE] ?>"></span> There is newer version <abbr title="according to YOUR version constraints">compatible with your project</abbr>. Update is recommended.</li>
<li><span class="<?php echo $classes[\ComposerUpdates\PackageInfo::STATUS_NOT_INSTALLED] ?>"></span> This library is not currently installed.</li>
</ul>
<table>
<thead>
<tr>
<th>Package</th>
<th>Version</th>
<th>Update</th>
<th>Compatible</th>
<th>Incompatible</th>
</tr>
</thead>
<tbody>
<?php foreach ($packages as $package) { ?>
<tr>
<td>
<?php if ($package->isUpdateAvailable()) { ?>
<span class="update-available"></span>
<?php } else { ?>
<span class="no-update"></span>
<?php } ?>
<span class="<?php echo $classes[$package->getStatus()] ?>"></span>
<?php echo str_replace('/', ' / ', $package->getName()) ?>
<?php if ($package->isDevOnly()) { ?>
<em>(dev only)</em>
<?php } ?>
</td>
<td>
<?php echo $package->getInstalledVersion() ?>
</td>
<td>
<?php if ($package->isUpdateAvailable()) { ?>
<?php echo $package->getAvailableVersion() ?> available
<?php if ($package->isCompatibleUpdateAvailable()) { ?>
<?php echo $package->getCompatibleUpdate() ?> available
<?php } ?>
</td>
<td>
<?php if ($package->isIncompatibleUpdateAvailable()) { ?>
<?php echo $package->getIncompatibleUpdate() ?> available
<?php } ?>
</td>
</tr>
Expand Down
30 changes: 24 additions & 6 deletions src/ComposerUpdates/Diagnostics/templates/tab.phtml
Original file line number Diff line number Diff line change
@@ -1,25 +1,43 @@
<style>
#nette-debug .nette-composerUpdatesTab .update-available,
#nette-debug .nette-composerUpdatesTab .no-update {
#nette-debug .nette-composerUpdatesTab .not-installed,
#nette-debug .nette-composerUpdatesTab .no-update,
#nette-debug .nette-composerUpdatesTab .incompatible-update,
#nette-debug .nette-composerUpdatesTab .compatible-update {
display: inline-block;
width: 16px;
height: 16px;
margin-top: 3px;
margin-bottom: -4px;
border-radius: 8px;
}
#nette-debug .nette-composerUpdatesTab .update-available {
background: #FFC029;
#nette-debug .nette-composerUpdatesTab .not-installed {
background: #B1B1B1;
}
#nette-debug .nette-composerUpdatesTab .no-update {
background: #599B4A;
}
#nette-debug .nette-composerUpdatesTab .incompatible-update {
background: #FFC029;
}
#nette-debug .nette-composerUpdatesTab .compatible-update {
background: #E60000;
}
</style>

<?php
$classes = array(
\ComposerUpdates\PackageInfo::STATUS_NOT_INSTALLED => 'not-installed',
\ComposerUpdates\PackageInfo::STATUS_NO_UPDATE => 'no-update',
\ComposerUpdates\PackageInfo::STATUS_INCOMPATIBLE_UPDATE => 'incompatible-update',
\ComposerUpdates\PackageInfo::STATUS_COMPATIBLE_UPDATE => 'compatible-update',
);
?>

<span title="Composer updates" class="nette-composerUpdatesTab">
<span class="<?php echo $classes[$status] ?>"></span>
<?php if (!$updates) { ?>
<span class="no-update"></span>&nbsp;up to date
no update
<?php } else { ?>
<span class="update-available"></span>&nbsp;<?php echo count($updates) . ' ' . (count($updates) === 1 ? 'update' : 'updates') ?>
<?php echo $updates . ' ' . ($updates === 1 ? 'update' : 'updates') ?>
<?php } ?>
</span>
14 changes: 7 additions & 7 deletions src/ComposerUpdates/Initializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class Initializer
{
private $cacheDir;
private $localConfigFile;
private $rootDir;

/** @var Composer\IO\IOInterface */
private $io;
Expand All @@ -23,16 +23,16 @@ class Initializer
/** @var Composer\Repository\RepositoryInterface */
private $installedRepository;

/** @var Composer\PAckage\RootPackageInterface */
/** @var Composer\Package\RootPackageInterface */
private $rootPackage;

/** @var Composer\DependencyResolver\Pool */
private $packagePool;

public function __construct($cacheDir, $localConfigFile)
public function __construct($cacheDir, $rootDir)
{
$this->cacheDir = $cacheDir . '/_ComposerUpdates';
$this->localConfigFile = $localConfigFile;
$this->cacheDir = $cacheDir . '/_ComposerUpdates.composer';
$this->rootDir = $rootDir;
$this->io = new Composer\IO\NullIO();
}

Expand Down Expand Up @@ -82,7 +82,7 @@ public function getDevRequires()
private function getConfig()
{
if ($this->config === NULL || $this->localConfig === NULL) {
$json = new Composer\Json\JsonFile($this->localConfigFile);
$json = new Composer\Json\JsonFile($this->rootDir . '/composer.json');
$this->localConfig = $json->read();

$this->config = new Composer\Config;
Expand All @@ -98,7 +98,7 @@ private function getConfig()

private function getVendorDir()
{
return dirname($this->localConfigFile) . '/' . $this->getConfig()->get('vendor-dir');
return $this->rootDir . '/' . $this->getConfig()->get('vendor-dir');
}

private function getRepositoryManager()
Expand Down
7 changes: 1 addition & 6 deletions src/ComposerUpdates/NullVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@

namespace ComposerUpdates;

use composer\Package\PackageInterface;

class NullVersion extends Version
{
protected $version;

protected $prettyVersion;

public function __construct()
{
$this->version = -1;
$this->prettyVersion = 'none';
}
}
Loading