Skip to content

Commit 7df9227

Browse files
Update CreateRelease.php
1 parent 018e8b6 commit 7df9227

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

packages/monorepo/src/Commands/CreateRelease.php

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,14 +370,16 @@ public function askForNewVersion(string $currentVersion): string
370370
$suggestedVersion = $currentVersion;
371371
} else {
372372
$this->line("Current version: {$currentVersion}");
373-
[$major, $minor, $patch] = explode('.', $currentVersion);
374-
$suggestedVersion = "$major.$minor.".((int) $patch + 1);
373+
$suggestedVersion = $this->suggestNextVersion($currentVersion);
375374
}
376375

376+
$this->line("Suggested next version: {$suggestedVersion}");
377+
$this->line('Examples: 3.1.5, 3.1.5-beta.1, 3.1.5-alpha.1, 3.1.5-rc.1');
378+
377379
$version = $this->ask('Enter the new version:', $suggestedVersion);
378380

379381
if (! $this->validateVersionFormat($version)) {
380-
$this->error('Invalid version format. Please use X.X.X format.');
382+
$this->error('Invalid version format. Please use X.X.X or X.X.X-prerelease format (alpha, beta, rc).');
381383

382384
return $this->askForNewVersion($currentVersion);
383385
}
@@ -394,14 +396,38 @@ public function askForNewVersion(string $currentVersion): string
394396
// Helper methods
395397
private function validateVersionFormat(string $version): bool
396398
{
397-
return preg_match('/^\\d+\\.\\d+\\.\\d+$/', $version);
399+
// Support both stable versions (X.X.X) and prerelease versions (X.X.X-alpha.X, X.X.X-beta.X, X.X.X-rc.X)
400+
return preg_match('/^\\d+\\.\\d+\\.\\d+(?:-(alpha|beta|rc)(?:\\.\\d+)?)?$/', $version);
398401
}
399402

400403
private function validateVersionOrder(string $newVersion, string $currentVersion): bool
401404
{
402405
return version_compare($newVersion, $currentVersion, '>=');
403406
}
404407

408+
private function suggestNextVersion(string $currentVersion): string
409+
{
410+
// Check if current version is a prerelease
411+
if (preg_match('/^(\d+)\.(\d+)\.(\d+)-(alpha|beta|rc)(?:\.(\d+))?$/', $currentVersion, $matches)) {
412+
$major = (int) $matches[1];
413+
$minor = (int) $matches[2];
414+
$patch = (int) $matches[3];
415+
$prerelease = $matches[4];
416+
$prereleaseVersion = isset($matches[5]) ? (int) $matches[5] : 1;
417+
418+
// For prerelease, suggest either next prerelease or stable version
419+
$nextPrerelease = "{$major}.{$minor}.{$patch}-{$prerelease}.".($prereleaseVersion + 1);
420+
$stableVersion = "{$major}.{$minor}.{$patch}";
421+
422+
// If it's rc, suggest stable version, otherwise suggest next prerelease
423+
return $prerelease === 'rc' ? $stableVersion : $nextPrerelease;
424+
} else {
425+
// For stable version, suggest next patch version
426+
[$major, $minor, $patch] = explode('.', $currentVersion);
427+
return "$major.$minor.".((int) $patch + 1);
428+
}
429+
}
430+
405431
// TODO: Not used anymore but propably helpfull
406432
// // Not used anymore but propably helpfull
407433
// protected function copyNewPackages(array $newPackages): bool

0 commit comments

Comments
 (0)