2018-01-07 07:00:47 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
|
|
use App\Console\BaseCommand;
|
|
|
|
use Symfony\Component\Yaml\Yaml;
|
|
|
|
|
|
|
|
class Version extends BaseCommand
|
|
|
|
{
|
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');
|
|
|
|
|
|
|
|
$version = $date.'-'.$version;
|
|
|
|
|
|
|
|
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-02-04 03:16:37 +08:00
|
|
|
if($this->option('write')) {
|
2018-01-20 01:08:43 +08:00
|
|
|
$version = $this->createVersionNumber($cfg);
|
2018-01-07 07:00:47 +08:00
|
|
|
$cfg['build']['number'] = $version;
|
|
|
|
file_put_contents($version_file, Yaml::dump($cfg, 4, 2));
|
|
|
|
}
|
|
|
|
|
2018-02-04 03:16:37 +08:00
|
|
|
# Only show the major.minor.patch version
|
|
|
|
if($this->option('base-only')) {
|
|
|
|
$version = 'v'.$cfg['current']['major'] . '.'
|
|
|
|
.$cfg['current']['minor'] . '.'
|
|
|
|
.$cfg['current']['patch'];
|
|
|
|
|
|
|
|
print $version;
|
|
|
|
} else {
|
|
|
|
$this->call('version:show', [
|
|
|
|
'--format' => 'compact',
|
|
|
|
'--suppress-app-name' => true
|
|
|
|
]);
|
|
|
|
}
|
2018-01-07 07:00:47 +08:00
|
|
|
}
|
|
|
|
}
|