Skip to content

Commit

Permalink
link to npm alpha version, GitHub tag, branch, or PR
Browse files Browse the repository at this point in the history
  • Loading branch information
tjenkinson committed Jun 30, 2020
1 parent dc62722 commit 21864c2
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions demo/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,29 @@ $(document).ready(function () {
$('#dumpfMP4').prop('checked', dumpfMP4);
$('#levelCapping').val(levelCapping);

// link to version on npm if canary
// github branch for a branch version
// github tag for a normal tag
// github PR for a pr
function getVersionLink (version) {
const alphaRegex = /[-.]0\.alpha\./;
const prRegex = /[-.]pr\.([^.]+)/;
const branchRegex = /[-.]branch\.([^.]+)/;
if (alphaRegex.test(version)) {
return `https://www.npmjs.com/package/hls.js/v/${encodeURIComponent(version)}`;
} else if (prRegex.test(version)) {
return `https://github.com/video-dev/hls.js/pull/${prRegex.exec(version)[1]}`;
} else if (branchRegex.test(version)) {
return `https://github.com/video-dev/hls.js/tree/${branchRegex.exec(version)[1]}`;
}
return `https://github.com/video-dev/hls.js/releases/tag/v${encodeURIComponent(version)}`;
}

const version = Hls.version;
const release = getReleaseVersion(version || '');
const versionLabel = version ? 'v' + version : 'releases';
$('h2').append('&nbsp;<a target=_blank href="https://github.com/video-dev/hls.js/releases/' +
(release ? 'tag/v' + release : '') + '">' + versionLabel + '</a>');
$('#currentVersion').html('Hls version:' + version);
if (version) {
const $a = $('<a />').attr('target', '_blank').attr('href', getVersionLink(version)).text('v' + version);
$('.title').append($a);
}

$('#streamURL').val(sourceURL);

Expand All @@ -130,19 +147,6 @@ $(document).ready(function () {
loadSelectedStream();
});

function getReleaseVersion (version) {
const ciBuildRegEx = /[-.](?:0\.alpha|pr|branch)\..+$/
if (ciBuildRegEx.test(version)) {
return version.replace(ciBuildRegEx, '').replace(/^(\d+\.\d+\.)(\d+)$/, function (version, majorMinor, ciPatch) {
if (ciPatch) {
return majorMinor + (parseInt(ciPatch, 10) - 1);
}
return version;
});
}
return version;
}

function setupGlobals () {
window.events = events = {
url: url,
Expand Down

0 comments on commit 21864c2

Please sign in to comment.