Adrià Vilanova Martínez | 0335b51 | 2022-01-21 13:34:59 +0100 | [diff] [blame] | 1 | // Returns whether the extension is a production version (released stable or |
| 2 | // beta version). |
| 3 | export function isProdVersion() { |
| 4 | // #!if production && !canary |
| 5 | return true; |
| 6 | // #!else |
| 7 | return false; |
| 8 | // #!endif |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 9 | } |
Adrià Vilanova Martínez | e32adc4 | 2021-08-30 17:16:49 +0200 | [diff] [blame] | 10 | |
| 11 | // Returns the extension version |
| 12 | export function getExtVersion() { |
| 13 | var manifest = chrome.runtime.getManifest(); |
| 14 | return manifest?.version; |
| 15 | } |
Adrià Vilanova Martínez | 5a8055b | 2022-09-29 13:05:19 +0200 | [diff] [blame] | 16 | |
Adrià Vilanova Martínez | f190585 | 2024-02-28 22:28:36 +0100 | [diff] [blame] | 17 | // Returns a semver-compatible extension version |
| 18 | export function getSemVerExtVersion() { |
| 19 | const version = getExtVersion(); |
| 20 | if (!(typeof version === 'string')) return null; |
| 21 | return version.match(/^[^.]*(?:\.[^.]*){0,2}/)?.[0] ?? null; |
| 22 | } |
| 23 | |
Adrià Vilanova Martínez | 5a8055b | 2022-09-29 13:05:19 +0200 | [diff] [blame] | 24 | // Get a URL to a document which is part of the extension documentation (using |
| 25 | // |ref| as the Git ref). |
| 26 | export function getDocURLWithRef(doc, ref) { |
| 27 | return 'https://gerrit.avm99963.com/plugins/gitiles/infinitegforums/+/' + |
| 28 | ref + '/docs/' + doc; |
| 29 | } |
| 30 | |
| 31 | // Get a URL to a document which is part of the extension documentation |
| 32 | // (autodetect the appropriate Git ref) |
| 33 | export function getDocURL(doc) { |
| 34 | if (!isProdVersion()) return getDocURLWithRef(doc, 'HEAD'); |
| 35 | |
| 36 | var version = getExtVersion(); |
| 37 | return getDocURLWithRef(doc, 'refs/tags/v' + version); |
| 38 | } |