(versionsObj, filepath, opts = {})
| 10 | |
| 11 | // return an array of versions that an article's product versions encompasses |
| 12 | function getApplicableVersions(versionsObj, filepath, opts = {}) { |
| 13 | if (typeof versionsObj === 'undefined') { |
| 14 | throw new Error(`No \`versions\` frontmatter found in ${filepath}`) |
| 15 | } |
| 16 | |
| 17 | // all versions are applicable! |
| 18 | if (versionsObj === '*') { |
| 19 | return allVersionKeys |
| 20 | } |
| 21 | |
| 22 | if (!featureData) { |
| 23 | featureData = getDeepDataByLanguage('features', 'en') |
| 24 | } |
| 25 | |
| 26 | // Check for frontmatter that includes a feature name, like: |
| 27 | // fpt: '*' |
| 28 | // feature: 'foo' |
| 29 | // or multiple feature names, like: |
| 30 | // fpt: '*' |
| 31 | // feature: ['foo', 'bar'] |
| 32 | // and add the versions affiliated with the feature (e.g., foo) to the frontmatter versions object: |
| 33 | // fpt: '*' |
| 34 | // ghes: '>=2.23' |
| 35 | // ghae: '*' |
| 36 | // where the feature is bringing the ghes and ghae versions into the mix. |
| 37 | const featureVersionsObj = reduce( |
| 38 | versionsObj, |
| 39 | (result, value, key) => { |
| 40 | if (key === 'feature') { |
| 41 | if (typeof value === 'string') { |
| 42 | Object.assign(result, { ...featureData[value].versions }) |
| 43 | } else if (Array.isArray(value)) { |
| 44 | value.forEach((str) => { |
| 45 | Object.assign(result, { ...featureData[str].versions }) |
| 46 | }) |
| 47 | } |
| 48 | delete result[key] |
| 49 | } |
| 50 | return result |
| 51 | }, |
| 52 | {} |
| 53 | ) |
| 54 | |
| 55 | // Get available versions for feature and standard versions. |
| 56 | const foundFeatureVersions = evaluateVersions(featureVersionsObj) |
| 57 | const foundStandardVersions = evaluateVersions(versionsObj) |
| 58 | |
| 59 | // Combine them! |
| 60 | const applicableVersions = Array.from(new Set(foundStandardVersions.concat(foundFeatureVersions))) |
| 61 | |
| 62 | if (!applicableVersions.length && !opts.doNotThrow) { |
| 63 | throw new Error( |
| 64 | `${filepath} is not available in any currently supported version. Make sure the \`versions\` property includes at least one supported version.` |
| 65 | ) |
| 66 | } |
| 67 | |
| 68 | // Sort them by the order in lib/all-versions. |
| 69 | let sortedVersions = sortBy(applicableVersions, (v) => { |
no test coverage detected