Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

get-applicable-versions.js 2.1 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  1. const allVersions = require('./all-versions')
  2. const versionSatisfiesRange = require('./version-satisfies-range')
  3. const checkIfNextVersionOnly = require('./check-if-next-version-only')
  4. // return an array of versions that an article's product versions encompasses
  5. function getApplicableVersions (frontmatterVersions, filepath) {
  6. if (typeof frontmatterVersions === 'undefined') {
  7. throw new Error(`No \`versions\` frontmatter found in ${filepath}`)
  8. }
  9. // all versions are applicable!
  10. if (frontmatterVersions === '*') {
  11. return Object.keys(allVersions)
  12. }
  13. // get an array like: [ 'free-pro-team@latest', 'enterprise-server@2.21', 'enterprise-cloud@latest' ]
  14. const applicableVersions = []
  15. let isNextVersionOnly = false
  16. // where frontmatter is something like:
  17. // free-pro-team: '*'
  18. // enterprise-server: '>=2.19'
  19. // enterprise-cloud: '*'
  20. // private-instances: '*'
  21. // ^ where each key corresponds to a plan
  22. Object.entries(frontmatterVersions)
  23. .forEach(([plan, planValue]) => {
  24. // Special handling for frontmatter that evalues to the next GHES release number or a hardcoded `next`.
  25. isNextVersionOnly = checkIfNextVersionOnly(planValue)
  26. // For each plan (e.g., enterprise-server), get matching versions from allVersions object
  27. Object.values(allVersions)
  28. .filter(relevantVersion => relevantVersion.plan === plan)
  29. .forEach(relevantVersion => {
  30. // Use a dummy value of '1.0' for non-numbered versions like free-pro-team and github-ae
  31. // This will evaluate to true against '*' but false against 'next', which is what we want.
  32. const versionToCompare = relevantVersion.hasNumberedReleases ? relevantVersion.currentRelease : '1.0'
  33. if (versionSatisfiesRange(versionToCompare, planValue)) {
  34. applicableVersions.push(relevantVersion.version)
  35. }
  36. })
  37. })
  38. if (!applicableVersions.length && !isNextVersionOnly) {
  39. throw new Error(`No applicable versions found for ${filepath}. Please double-check the page's \`versions\` frontmatter.`)
  40. }
  41. return applicableVersions
  42. }
  43. module.exports = getApplicableVersions
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...