Skip to content

Commit ae08940

Browse files
committed
!410 - Add more version options including pre release, custom, build meta.
1 parent 25a6deb commit ae08940

File tree

9 files changed

+313
-66
lines changed

9 files changed

+313
-66
lines changed

apps/Core/Components/Devtools/Modules/ModulesComponent.php

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
namespace Apps\Core\Components\Devtools\Modules;
44

55
use Apps\Core\Packages\Devtools\Modules\DevtoolsModules;
6-
76
use System\Base\BaseComponent;
7+
use z4kn4fein\SemVer\Version;
88

99
class ModulesComponent extends BaseComponent
1010
{
@@ -313,10 +313,59 @@ public function viewAction()
313313
$moduleArr = $module['module_details'];
314314
$moduleArr['module_details'] = $module['module_details'];
315315

316-
$this->view->module = $moduleArr;
317-
} else {
318-
$this->view->module = $module;
316+
$module = $moduleArr;
317+
}
318+
319+
if ($this->view->newrelease) {
320+
$module['isPreRelease'] = false;
321+
$module['preRelease'] = false;
322+
$module['buildMeta'] = false;
323+
$module['isCustom'] = false;
324+
325+
$module['version'] = 'v1.0';
326+
if ($module['version'] !== '0.0.0') {
327+
try {
328+
$parsedVersion = Version::parse($module['version']);
329+
330+
$module['isPreRelease'] = $parsedVersion->isPreRelease();
331+
332+
if ($module['isPreRelease']) {
333+
$preRelease = $parsedVersion->getPreRelease();
334+
335+
if ($preRelease) {
336+
$preRelease = explode('.', $preRelease);
337+
if (count($preRelease) > 1) {
338+
unset($preRelease[$this->helper->lastKey($preRelease)]);
339+
}
340+
$module['preRelease'] = implode('.', $preRelease);
341+
}
342+
343+
$buildMeta = $parsedVersion->getBuildMeta();
344+
if ($buildMeta) {
345+
$buildMeta = explode('.', $buildMeta);
346+
array_walk($buildMeta, function(&$meta) {
347+
if ((int) $meta !== 0) {
348+
try {
349+
$metaIsUnixTime = \Carbon\Carbon::parse((int) $meta);
350+
351+
if ($metaIsUnixTime) {
352+
$meta = 'now';
353+
}
354+
} catch (\Exception $e) {
355+
// Do nothing
356+
}
357+
}
358+
});
359+
$module['buildMeta'] = implode('.', $buildMeta);
360+
}
361+
}
362+
} catch (\Exception $e) {
363+
$module['isCustom'] = true;
364+
}
365+
}
319366
}
367+
368+
$this->view->module = $module;
320369
}
321370
} else if (isset($this->getData()['id']) &&
322371
isset($this->getData()['bundles'])

apps/Core/Packages/Devtools/Modules/DevtoolsModules.php

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,6 @@ protected function getReleases($module, $getLatestRelease = false)
12191219

12201220
$this->addResponse($e->getMessage(), 1);
12211221
}
1222-
12231222
if (isset($releases) && is_array($releases)) {
12241223
if (count($releases) === 1 || $getLatestRelease) {
12251224
return $releases[0];
@@ -1278,6 +1277,10 @@ protected function initApi($data)
12781277

12791278
public function bumpVersion($data)
12801279
{
1280+
if (isset($data['bump']) && $data['bump'] === 'custom') {
1281+
return false;
1282+
}
1283+
12811284
if (!isset($data['repo'])) {
12821285
$module = $this->modules->{$data['module_type']}->getById($data['id']);
12831286

@@ -1294,18 +1297,69 @@ public function bumpVersion($data)
12941297
}
12951298

12961299
$module['repo'] = $this->helper->last(explode('/', $module['repo']));
1300+
$module['bump'] = $data['bump'];
12971301
} else {
12981302
$module = $data;
12991303
}
13001304

1305+
if (isset($data['preReleasePrefix']) || isset($data['buildMetaPrefix'])) {
1306+
if (isset($data['preReleasePrefix'])) {
1307+
if (!checkCtype($data['preReleasePrefix'], 'alpha', ['.'])) {
1308+
$this->addResponse('Pre release prefix cannot have special chars or numbers (except .(dot)).', 1);
1309+
return false;
1310+
}
1311+
$module['preReleasePrefix'] = $data['preReleasePrefix'];
1312+
}
1313+
if (isset($data['buildMetaPrefix'])) {
1314+
if (!checkCtype($data['buildMetaPrefix'], 'alpha', ['.'])) {
1315+
$this->addResponse('Build meta prefix cannot have special chars or numbers (except .(dot)).', 1);
1316+
return false;
1317+
}
1318+
$module['buildMetaPrefix'] = $data['buildMetaPrefix'];
1319+
}
1320+
}
1321+
13011322
$latestRelease = $this->getReleases($module, true);
13021323

13031324
if ($latestRelease) {
13041325
$latestReleaseVersion = $latestRelease['name'];
13051326
} else {
1306-
$this->addResponse('No version found on remote repository.', 1, ['release' => $module['version']]);
1327+
$moduleVersion = $module['version'];
13071328

1308-
return false;
1329+
if (isset($module['preReleasePrefix']) || isset($module['buildMetaPrefix'])) {
1330+
if (isset($module['preReleasePrefix'])) {
1331+
$moduleVersion = $moduleVersion . '-' . $module['preReleasePrefix'];
1332+
}
1333+
1334+
if (isset($module['buildMetaPrefix'])) {
1335+
$module['buildMetaPrefix'] = explode('.', $module['buildMetaPrefix']);
1336+
1337+
array_walk($module['buildMetaPrefix'], function(&$prefix) {
1338+
if ($prefix === 'now') {
1339+
$prefix = time();
1340+
}
1341+
});
1342+
$moduleVersion = $moduleVersion . '+' . implode('.', $module['buildMetaPrefix']);
1343+
}
1344+
}
1345+
1346+
$parsedVersion = Version::parse($moduleVersion);
1347+
1348+
$parsedVersionString = null;
1349+
1350+
if (isset($module['preReleasePrefix']) || isset($module['buildMetaPrefix'])) {
1351+
$parsedVersion = $parsedVersion->getNextPreReleaseVersion();
1352+
1353+
$parsedVersionString = $parsedVersion->__toString();
1354+
1355+
if (isset($module['buildMetaPrefix'])) {
1356+
$parsedVersionString = $parsedVersionString . '+' . implode('.', $module['buildMetaPrefix']);
1357+
}
1358+
}
1359+
1360+
$this->addResponse('No version found on remote repository.', 1, ['release' => $parsedVersionString ?? $moduleVersion]);
1361+
1362+
return $parsedVersionString ?? $moduleVersion;
13091363
}
13101364

13111365
if ($module['module_type'] === 'core') {
@@ -1331,7 +1385,9 @@ public function bumpVersion($data)
13311385
}
13321386

13331387
$version = Version::parse($currentVersion);
1334-
$bump = 'getNext' . ucfirst($data['bump']) . 'Version';
1388+
trace([$version]);
1389+
$bump = 'getNext' . ucfirst($module['bump']) . 'Version';
1390+
13351391
$newVersion = $version->$bump();
13361392

13371393
if ($newVersion) {
@@ -1417,16 +1473,10 @@ public function generateRelease($data)
14171473
// }
14181474

14191475
$prerelease = false;
1420-
if ($data['bump'] == 'preRelease') {
1476+
if ($data['bump'] == 'preRelease' || $data['bump'] == 'buildMeta' || $data['bump'] == 'preReleaseBuildMeta') {
14211477
$prerelease = true;
14221478
}
1423-
1424-
if ($data['bump'] === 'buildMeta') {
1425-
$name = $data['buildMetaRelease'];
1426-
$prerelease = true;
1427-
} else {
1428-
$name = $this->bumpVersion($data);
1429-
}
1479+
$name = $this->bumpVersion($data);
14301480

14311481
if (!$name) {
14321482
$name = $module['version'];

apps/Core/Views/Default/html/devtools/modules/module.html

Lines changed: 101 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -105,45 +105,91 @@
105105
afterInit : function() {
106106
$('#{{componentId}}-{{sectionId}}-release-type').on('select2:select', function(e) {
107107
var bump = e.params.data.id;
108-
if (bump === 'buildMeta') {
109-
$('#{{componentId}}-{{sectionId}}-build-meta').attr('disabled', false);
110-
$('#{{componentId}}-{{sectionId}}-build-meta').val($('#{{componentId}}-{{sectionId}}-version').val());
111-
$('#{{componentId}}-{{sectionId}}-release-version').html(
112-
'<h4 class="mt-1" id="build-meta-release">' +
113-
$('#{{componentId}}-{{sectionId}}-build-meta').val() +
114-
'</h4>'
115-
);
116-
$('#{{componentId}}-{{sectionId}}-build-meta').off();
117-
$('#{{componentId}}-{{sectionId}}-build-meta').keyup(function() {
118-
$('#{{componentId}}-{{sectionId}}-release-version').html(
119-
'<h4 class="mt-1" id="build-meta-release">' +
120-
$('#{{componentId}}-{{sectionId}}-build-meta').val() +
121-
'</h4>'
122-
);
123-
});
124108

125-
return;
109+
if (bump === 'custom') {
110+
$('#{{componentId}}-{{sectionId}}-pre-release-prefix').val('');
111+
$('#{{componentId}}-{{sectionId}}-build-meta-prefix').val('');
112+
$('#{{componentId}}-{{sectionId}}-pre-release-prefix').attr('disabled', true);
113+
$('#{{componentId}}-{{sectionId}}-build-meta-prefix').attr('disabled', true);
114+
$('#{{componentId}}-{{sectionId}}-custom-version').attr('disabled', false);
115+
$('#semver').attr('hidden', true);
116+
$('#custom').attr('hidden', false);
117+
$('#{{componentId}}-{{sectionId}}-get-next-release').attr('disabled', true);
126118
} else {
127-
$('#{{componentId}}-{{sectionId}}-build-meta').val('');
128-
$('#{{componentId}}-{{sectionId}}-build-meta').attr('disabled', true);
129-
$('#{{componentId}}-{{sectionId}}-release-version').html('<h4 class="mt-1">SELECT RELEASE TYPE</h4>');
119+
$('#semver').attr('hidden', false);
120+
$('#custom').attr('hidden', true);
121+
$('#{{componentId}}-{{sectionId}}-custom-version').val('');
122+
123+
if (bump === 'buildMeta') {
124+
$('#{{componentId}}-{{sectionId}}-build-meta-prefix').val('');
125+
$('#{{componentId}}-{{sectionId}}-pre-release-prefix').val('');
126+
$('#{{componentId}}-{{sectionId}}-build-meta-prefix').attr('disabled', false);
127+
$('#{{componentId}}-{{sectionId}}-pre-release-prefix').attr('disabled', true);
128+
} else if (bump === 'preRelease') {
129+
$('#{{componentId}}-{{sectionId}}-pre-release-prefix').val('');
130+
$('#{{componentId}}-{{sectionId}}-build-meta-prefix').val('');
131+
$('#{{componentId}}-{{sectionId}}-pre-release-prefix').attr('disabled', false);
132+
$('#{{componentId}}-{{sectionId}}-build-meta-prefix').attr('disabled', true);
133+
} else if (bump === 'preReleaseBuildMeta') {
134+
$('#{{componentId}}-{{sectionId}}-pre-release-prefix').val('');
135+
$('#{{componentId}}-{{sectionId}}-build-meta-prefix').val('');
136+
$('#{{componentId}}-{{sectionId}}-pre-release-prefix').attr('disabled', false);
137+
$('#{{componentId}}-{{sectionId}}-build-meta-prefix').attr('disabled', false);
138+
}
139+
140+
$('#{{componentId}}-{{sectionId}}-get-next-release').attr('disabled', false);
130141
}
142+
$('#release-version-text').html('');
143+
});
131144

132-
$('#{{componentId}}-{{sectionId}}-release-version').html(
133-
'<div class="row">' +
134-
' <div class="col text-lg">' +
135-
' <i class="fa fa-cog fa-spin"></i> Loading...' +
136-
' </div>' +
137-
'</div>'
138-
);
145+
$('#{{componentId}}-{{sectionId}}-get-next-release').off();
146+
$('#{{componentId}}-{{sectionId}}-get-next-release').click(function(e) {
147+
e.preventDefault();
148+
var bump = $('#{{componentId}}-{{sectionId}}-release-type').val();
139149

150+
if (bump === 'custom') {
151+
return;
152+
}
140153

141154
var postData = { };
142155
postData[$('#security-token').attr('name')] = $('#security-token').val();
143156
postData['id'] = $('#{{componentId}}-{{sectionId}}-id').val();
144157
postData['module_type'] = $('#{{componentId}}-{{sectionId}}-module_type').val();
145158
postData['bump'] = bump;
146159

160+
if (bump === 'preRelease') {
161+
postData['preReleasePrefix'] = $('#{{componentId}}-{{sectionId}}-pre-release-prefix').val();
162+
if (postData['preReleasePrefix'] === '') {
163+
PNotify.error({'text': 'Provide pre-release prefix.'});
164+
return;
165+
}
166+
} else if (bump === 'buildMeta') {
167+
postData['buildMetaPrefix'] = $('#{{componentId}}-{{sectionId}}-build-meta-prefix').val();
168+
if (postData['buildMetaPrefix'] === '') {
169+
PNotify.error({'text': 'Provide build meta prefix.'});
170+
return;
171+
}
172+
} else if (bump === 'preReleaseBuildMeta') {
173+
postData['preReleasePrefix'] = $('#{{componentId}}-{{sectionId}}-pre-release-prefix').val();
174+
postData['buildMetaPrefix'] = $('#{{componentId}}-{{sectionId}}-build-meta-prefix').val();
175+
if (postData['preReleasePrefix'] === '') {
176+
PNotify.error({'text': 'Provide pre-release prefix.'});
177+
return;
178+
}
179+
if (postData['buildMetaPrefix'] === '') {
180+
PNotify.error({'text': 'Provide build meta prefix.'});
181+
return;
182+
}
183+
}
184+
$('#release-version-text').html(
185+
'<div class="row">' +
186+
' <div class="col text-lg">' +
187+
' <i class="fa fa-cog fa-spin"></i> Loading...' +
188+
' </div>' +
189+
'</div>'
190+
);
191+
192+
147193
$.post('{{links.url("devtools/modules/bumpVersion")}}', postData, function(response) {
148194
if (response.tokenKey && response.token) {
149195
$('#security-token').attr('name', response.tokenKey);
@@ -161,19 +207,19 @@
161207
}
162208

163209
if (response.responseData && response.responseData.currentVersion && response.responseData.newVersion) {
164-
$('#{{componentId}}-{{sectionId}}-release-version').html(
210+
$('#release-version-text').html(
165211
'<h4><span class="text-' + color + '">' + response.responseData.currentVersion + '</span> ' +
166212
'<i class="fa-solid fa-arrow-right"></i> ' +
167213
'<span class="text-primary">' + response.responseData.newVersion + '</span></h4>'
168214
);
169215
}
170216
} else {
171217
if (response.responseData && response.responseData.release) {
172-
$('#{{componentId}}-{{sectionId}}-release-version').html(
218+
$('#release-version-text').html(
173219
'<h4><span class="text-primary">' + response.responseData.release + '</span></h4>'
174220
);
175221
} else {
176-
$('#{{componentId}}-{{sectionId}}-release-version').html(
222+
$('#release-version-text').html(
177223
'<span class="text-danger">ERROR LOADING RELEASE INFORMATION!</span>'
178224
);
179225
}
@@ -198,8 +244,29 @@
198244

199245
var postData = { };
200246
postData['bump'] = $('#{{componentId}}-{{sectionId}}-release-type').val();
201-
if (postData['bump'] === 'buildMeta') {
202-
postData['buildMetaRelease'] = $('#build-meta-release').html();
247+
if (postData['bump'] === 'preRelease') {
248+
postData['preReleasePrefix'] = $('#{{componentId}}-{{sectionId}}-pre-release-prefix').val();
249+
if (postData['preReleasePrefix'] === '') {
250+
PNotify.error({'text': 'Provide pre-release prefix.'});
251+
return;
252+
}
253+
} else if (postData['bump'] === 'buildMeta') {
254+
postData['buildMetaPrefix'] = $('#{{componentId}}-{{sectionId}}-build-meta-prefix').val();
255+
if (postData['buildMetaPrefix'] === '') {
256+
PNotify.error({'text': 'Provide build meta prefix.'});
257+
return;
258+
}
259+
} else if (postData['bump'] === 'preReleaseBuildMeta') {
260+
postData['preReleasePrefix'] = $('#{{componentId}}-{{sectionId}}-pre-release-prefix').val();
261+
postData['buildMetaPrefix'] = $('#{{componentId}}-{{sectionId}}-build-meta-prefix').val();
262+
if (postData['preReleasePrefix'] === '') {
263+
PNotify.error({'text': 'Provide pre-release prefix.'});
264+
return;
265+
}
266+
if (postData['buildMetaPrefix'] === '') {
267+
PNotify.error({'text': 'Provide build meta prefix.'});
268+
return;
269+
}
203270
}
204271
postData[$('#security-token').attr('name')] = $('#security-token').val();
205272
postData['id'] = $('#{{componentId}}-{{sectionId}}-id').val();
@@ -244,8 +311,9 @@
244311
});
245312
}
246313
},
247-
'{{componentId}}-{{sectionId}}-build-meta' : { },
248314
'{{componentId}}-{{sectionId}}-pre-release-prefix' : { },
315+
'{{componentId}}-{{sectionId}}-build-meta-prefix' : { },
316+
'{{componentId}}-{{sectionId}}-custom-version' : { },
249317
'{{componentId}}-{{sectionId}}-branch' : {
250318
placeholder : "SELECT BRANCH",
251319
afterInit : function() {

0 commit comments

Comments
 (0)