├── src ├── Traits │ └── Executable.php ├── Command │ ├── Check.php │ ├── Reset.php │ ├── Generate.php │ └── Up.php ├── Library │ ├── GitTag.php │ └── Git.php ├── Provider │ └── VersionServiceProvider.php └── Helper │ └── Version.php ├── composer.json └── README.md /src/Traits/Executable.php: -------------------------------------------------------------------------------- 1 | run(); 18 | 19 | if ($code) { 20 | throw new RuntimeException($process->getErrorOutput()); 21 | } 22 | 23 | return $process; 24 | } 25 | } -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ismailocal/laravel-version", 3 | "description": "Version manager for laravel projects", 4 | "type": "library", 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "İsmail Öcal", 9 | "email": "ismailocal@gmail.com" 10 | } 11 | ], 12 | "autoload": { 13 | "psr-4": { 14 | "LaravelVersion\\": "src/" 15 | } 16 | }, 17 | "extra": { 18 | "laravel": { 19 | "providers": [ 20 | "LaravelVersion\\Provider\\VersionServiceProvider" 21 | ] 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Command/Check.php: -------------------------------------------------------------------------------- 1 | output->writeln(Version::toString()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Library/GitTag.php: -------------------------------------------------------------------------------- 1 | version = $version; 21 | } 22 | 23 | /** 24 | * @return $this 25 | */ 26 | public function add() 27 | { 28 | $this->exec("git tag -a {$this->version} -m 'v{$this->version}'"); 29 | 30 | return $this; 31 | } 32 | 33 | /** 34 | * @return $this 35 | */ 36 | public function push() 37 | { 38 | $this->exec("git push origin {$this->version}"); 39 | 40 | return $this; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Command/Reset.php: -------------------------------------------------------------------------------- 1 | output->writeln(Version::toString()); 30 | if($version){ 31 | $this->output->writeln('Version resetted.'); 32 | }else{ 33 | $this->output->writeln('Version not resetted!'); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Command/Generate.php: -------------------------------------------------------------------------------- 1 | output->writeln(Version::toString()); 31 | if($version){ 32 | $this->output->writeln('Version generated.'); 33 | }else{ 34 | $this->output->writeln('Version not generated!'); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Library/Git.php: -------------------------------------------------------------------------------- 1 | version = $version; 18 | } 19 | 20 | /** 21 | * @return $this 22 | */ 23 | public function add() 24 | { 25 | $this->exec('git add version.json'); 26 | 27 | return $this; 28 | } 29 | 30 | /** 31 | * @return $this 32 | */ 33 | public function commit() 34 | { 35 | $this->exec("git commit -m '{$this->version} version up'"); 36 | 37 | return $this; 38 | } 39 | 40 | /** 41 | * @return $this 42 | */ 43 | public function push() 44 | { 45 | $this->exec('git push'); 46 | 47 | return $this; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Version manager for laravel projects 2 | 3 | Semantic versioning for laravel project like {major.minor.patch}. 4 | 5 | For example 0.1.2 6 | 7 | ## Install package 8 | ```` 9 | composer require ismailocal/laravel-version 10 | ```` 11 | 12 | ## Version generate 13 | ```` 14 | php artisan version:generate 15 | ```` 16 | Now you can find version.json file in your base_path. 17 | 18 | ## Version reset 19 | ```` 20 | php artisan version:reset 21 | ```` 22 | 23 | ## Version check 24 | ```` 25 | php artisan version:check 26 | ```` 27 | 28 | ## Version up 29 | ```` 30 | php artisan version:up {level} 31 | ```` 32 | {level} can be one of major,minor or patch 33 | 34 | Version up command upgrading your current version in version.json. 35 | 36 | Then after that version.json file will be commit and push your current branch on your repo. 37 | 38 | If this process successfuly done then that version will be tag and push your current repo. 39 | 40 | ## Use in blade 41 | ```` 42 | @version 43 | ```` 44 | -------------------------------------------------------------------------------- /src/Provider/VersionServiceProvider.php: -------------------------------------------------------------------------------- 1 | commands([ 38 | Generate::class, 39 | Reset::class, 40 | Up::class, 41 | Check::class, 42 | ]); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Command/Up.php: -------------------------------------------------------------------------------- 1 | argument('level')); 31 | $this->output->writeln(Version::toString()); 32 | if ($version) { 33 | try { 34 | $git = new Git(Version::toString()); 35 | $git->add()->commit()->push(); 36 | $this->output->writeln('Git pushed.'); 37 | 38 | $gitTag = new GitTag(Version::toString()); 39 | $gitTag->add()->push(); 40 | $this->output->writeln('Git pushed tag.'); 41 | 42 | $this->output->writeln('Version upped.'); 43 | } catch (\Exception $exception) { 44 | $this->output->writeln('Version rollback!.'); 45 | Version::rollback(); 46 | throw $exception; 47 | } 48 | } else { 49 | $this->output->writeln('Version not upped!'); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Helper/Version.php: -------------------------------------------------------------------------------- 1 | 0, 17 | 'minor' => 0, 18 | 'patch' => 0 19 | ]; 20 | } 21 | 22 | /** 23 | * @return string 24 | */ 25 | private static function getPath() 26 | { 27 | return base_path('version.json'); 28 | } 29 | 30 | /** 31 | * @return bool 32 | */ 33 | public static function reset() 34 | { 35 | $path = static::getPath(); 36 | 37 | if (file_exists($path)) { 38 | unlink($path); 39 | } 40 | 41 | return static::generate(); 42 | } 43 | 44 | /** 45 | * @return bool 46 | */ 47 | public static function generate() 48 | { 49 | $path = static::getPath(); 50 | 51 | if (!file_exists($path)) { 52 | file_put_contents($path, json_encode(static::initialVersion())); 53 | return true; 54 | } 55 | 56 | return false; 57 | } 58 | 59 | /** 60 | * @return array|mixed 61 | */ 62 | public static function version() 63 | { 64 | $path = static::getPath(); 65 | 66 | if (file_exists($path)) { 67 | return json_decode(file_get_contents($path), true); 68 | } 69 | 70 | return []; 71 | } 72 | 73 | /** 74 | * @param $level 75 | * @return bool 76 | */ 77 | public static function up($level) 78 | { 79 | static::$version = static::version(); 80 | 81 | $version = static::$version; 82 | 83 | $up = false; 84 | foreach ($version as $key => $value) { 85 | if ($key === $level) { 86 | $up = true; 87 | $version[$key] += 1; 88 | } else if ($up) { 89 | $version[$key] = 0; 90 | } 91 | } 92 | 93 | $path = static::getPath(); 94 | if (file_exists($path)) { 95 | file_put_contents($path, json_encode($version)); 96 | return true; 97 | } 98 | 99 | return false; 100 | } 101 | 102 | /** 103 | * @return bool 104 | */ 105 | public static function rollback() 106 | { 107 | $path = static::getPath(); 108 | if (file_exists($path) && static::$version) { 109 | file_put_contents($path, json_encode(static::$version)); 110 | return true; 111 | } 112 | } 113 | 114 | /** 115 | * @return string 116 | */ 117 | public static function toString() 118 | { 119 | return implode('.', static::version()); 120 | } 121 | } 122 | --------------------------------------------------------------------------------