a58bca390b
* Fix BindingResolutionError when debug toolbar isn't present * Formatting
65 lines
2.2 KiB
PHP
65 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Contracts\Command;
|
|
use App\Services\VersionService;
|
|
use Symfony\Component\Yaml\Yaml;
|
|
|
|
class Version extends Command
|
|
{
|
|
protected $signature = 'phpvms:version {--write} {--base-only} {--write-full-version} {version?}';
|
|
|
|
private $versionSvc;
|
|
|
|
public function __construct(VersionService $versionSvc)
|
|
{
|
|
parent::__construct();
|
|
|
|
$this->versionSvc = $versionSvc;
|
|
}
|
|
|
|
/**
|
|
* Run dev related commands
|
|
*
|
|
* @throws \Symfony\Component\Yaml\Exception\ParseException
|
|
*/
|
|
public function handle()
|
|
{
|
|
if ($this->option('write')) {
|
|
// Write the updated build number out to the file
|
|
$version_file = config_path('version.yml');
|
|
$cfg = Yaml::parse(file_get_contents($version_file));
|
|
|
|
// If a version is being passed in, the update the build, etc data against this
|
|
if ($this->argument('version')) {
|
|
$version = \SemVer\SemVer\Version::fromString($this->argument('version'));
|
|
if ($this->option('write_full_version')) {
|
|
$cfg['current']['major'] = $version->getMajor();
|
|
$cfg['current']['minor'] = $version->getMinor();
|
|
$cfg['current']['patch'] = $version->getPatch();
|
|
}
|
|
|
|
$prerelease = $version->getPreRelease();
|
|
if (strpos($prerelease, '.') !== false) {
|
|
$prerelease = explode('.', $prerelease);
|
|
$cfg['current']['prerelease'] = $prerelease[0];
|
|
$cfg['current']['buildmetadata'] = $prerelease[1];
|
|
} else {
|
|
$cfg['current']['prerelease'] = $prerelease;
|
|
}
|
|
}
|
|
|
|
// Always write out the build ID/build number which is the commit hash
|
|
$build_number = $this->versionSvc->getBuildId($cfg);
|
|
$cfg['current']['commit'] = $build_number;
|
|
$cfg['build']['number'] = $build_number;
|
|
|
|
file_put_contents($version_file, Yaml::dump($cfg, 4, 2));
|
|
}
|
|
|
|
$version = $this->versionSvc->getCurrentVersion(!$this->option('base-only'));
|
|
echo $version."\n";
|
|
}
|
|
}
|