2018-01-07 07:00:47 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
use App\Console\Command;
|
2018-01-07 07:00:47 +08:00
|
|
|
use Symfony\Component\Yaml\Yaml;
|
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
/**
|
|
|
|
* Class Version
|
|
|
|
* @package App\Console\Commands
|
|
|
|
*/
|
|
|
|
class Version extends Command
|
2018-01-07 07:00:47 +08:00
|
|
|
{
|
2018-02-04 03:16:37 +08:00
|
|
|
protected $signature = 'phpvms:version {--write} {--base-only}';
|
2018-01-07 07:00:47 +08:00
|
|
|
|
2018-01-20 01:08:43 +08:00
|
|
|
/**
|
|
|
|
* Create the version number that gets written out
|
|
|
|
*/
|
|
|
|
protected function createVersionNumber($cfg)
|
|
|
|
{
|
|
|
|
exec($cfg['git']['git-local'], $version);
|
|
|
|
$version = substr($version[0], 0, $cfg['build']['length']);
|
|
|
|
|
|
|
|
# prefix with the date in YYMMDD format
|
|
|
|
$date = date('ymd');
|
2018-03-20 09:50:40 +08:00
|
|
|
$version = $date.'-'.$version;
|
2018-01-20 01:08:43 +08:00
|
|
|
|
|
|
|
return $version;
|
|
|
|
}
|
|
|
|
|
2018-01-07 07:00:47 +08:00
|
|
|
/**
|
|
|
|
* Run dev related commands
|
|
|
|
* @throws \Symfony\Component\Yaml\Exception\ParseException
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2018-02-04 03:16:37 +08:00
|
|
|
$version_file = config_path('version.yml');
|
|
|
|
$cfg = Yaml::parse(file_get_contents($version_file));
|
2018-01-20 01:08:43 +08:00
|
|
|
|
2018-03-08 00:24:29 +08:00
|
|
|
# Get the current build id
|
|
|
|
$build_number = $this->createVersionNumber($cfg);
|
|
|
|
$cfg['build']['number'] = $build_number;
|
|
|
|
|
|
|
|
$c = $cfg['current'];
|
|
|
|
$version = "v{$c['major']}.{$c['minor']}.{$c['patch']}-{$build_number}";
|
|
|
|
|
2018-03-08 22:51:36 +08:00
|
|
|
if ($this->option('write')) {
|
2018-01-07 07:00:47 +08:00
|
|
|
file_put_contents($version_file, Yaml::dump($cfg, 4, 2));
|
|
|
|
}
|
|
|
|
|
2018-03-08 22:16:42 +08:00
|
|
|
# Only show the major.minor.patch version
|
|
|
|
if ($this->option('base-only')) {
|
2018-03-20 09:50:40 +08:00
|
|
|
$version = 'v'.$cfg['current']['major'].'.'
|
|
|
|
.$cfg['current']['minor'].'.'
|
|
|
|
.$cfg['current']['patch'];
|
2018-03-08 22:16:42 +08:00
|
|
|
}
|
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
print $version."\n";
|
2018-01-07 07:00:47 +08:00
|
|
|
}
|
|
|
|
}
|