2018-01-07 07:00:47 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
2019-09-17 01:08:26 +08:00
|
|
|
use App\Contracts\Command;
|
2019-08-07 05:48:00 +08:00
|
|
|
use App\Services\VersionService;
|
2018-01-07 07:00:47 +08:00
|
|
|
use Symfony\Component\Yaml\Yaml;
|
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
class Version extends Command
|
2018-01-07 07:00:47 +08:00
|
|
|
{
|
2019-12-12 01:57:18 +08:00
|
|
|
protected $signature = 'phpvms:version {--write} {--base-only} {--write-full-version} {version?}';
|
2018-01-07 07:00:47 +08:00
|
|
|
|
2019-08-07 05:48:00 +08:00
|
|
|
private $versionSvc;
|
2018-01-20 01:08:43 +08:00
|
|
|
|
2019-08-07 05:48:00 +08:00
|
|
|
public function __construct(VersionService $versionSvc)
|
|
|
|
{
|
|
|
|
parent::__construct();
|
2019-08-11 08:42:35 +08:00
|
|
|
|
2019-08-07 05:48:00 +08:00
|
|
|
$this->versionSvc = $versionSvc;
|
2018-01-20 01:08:43 +08:00
|
|
|
}
|
|
|
|
|
2018-01-07 07:00:47 +08:00
|
|
|
/**
|
|
|
|
* Run dev related commands
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-01-07 07:00:47 +08:00
|
|
|
* @throws \Symfony\Component\Yaml\Exception\ParseException
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2018-03-08 22:51:36 +08:00
|
|
|
if ($this->option('write')) {
|
2019-12-12 01:57:18 +08:00
|
|
|
// Write the updated build number out to the file
|
2019-08-07 05:48:00 +08:00
|
|
|
$version_file = config_path('version.yml');
|
|
|
|
$cfg = Yaml::parse(file_get_contents($version_file));
|
2019-12-12 01:57:18 +08:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-07 05:48:00 +08:00
|
|
|
$build_number = $this->versionSvc->getBuildId($cfg);
|
2019-12-12 01:57:18 +08:00
|
|
|
$cfg['current']['commit'] = $build_number;
|
2019-08-07 05:48:00 +08:00
|
|
|
$cfg['build']['number'] = $build_number;
|
2018-01-07 07:00:47 +08:00
|
|
|
|
2019-08-07 05:48:00 +08:00
|
|
|
file_put_contents($version_file, Yaml::dump($cfg, 4, 2));
|
2018-03-08 22:16:42 +08:00
|
|
|
}
|
|
|
|
|
2019-08-07 05:48:00 +08:00
|
|
|
$version = $this->versionSvc->getCurrentVersion(!$this->option('base-only'));
|
2018-08-27 00:40:04 +08:00
|
|
|
echo $version."\n";
|
2018-01-07 07:00:47 +08:00
|
|
|
}
|
|
|
|
}
|