add version directories for rest data (#34826)
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
import enterpriseServerReleases from './enterprise-server-releases.js'
|
||||
|
||||
// version = "plan"@"release"
|
||||
// example: enterprise-server@2.21
|
||||
// where "enterprise-server" is the plan and "2.21" is the release
|
||||
const versionDelimiter = '@'
|
||||
const latestNonNumberedRelease = 'latest'
|
||||
const REST_DATA_META_FILE = 'src/rest/data/meta.json'
|
||||
|
||||
// !Explanation of versionless redirect fallbacks!
|
||||
// This array is **in order** of the versions the site should try to fall back to if
|
||||
@@ -94,26 +93,13 @@ plans.forEach((planObj) => {
|
||||
})
|
||||
})
|
||||
|
||||
const apiFilesPath = path.join(process.cwd(), 'src/rest/data')
|
||||
// This is what determines which versions are calendar date versioned for the REST API docs
|
||||
// This is the source of truth for which versions are calendar date versioned.
|
||||
fs.readdirSync(apiFilesPath)
|
||||
.filter((file) => file.endsWith('.json'))
|
||||
.forEach((file) => {
|
||||
const fileName = file.split('.json')[0]
|
||||
const version = getDocsVersion(fileName)
|
||||
const apiVersion = fileName.split(allVersions[version].openApiVersionName)[1].replace('.', '')
|
||||
|
||||
if (apiVersion !== '') {
|
||||
allVersions[version].apiVersions.push(apiVersion)
|
||||
if (
|
||||
allVersions[version].latestApiVersion === '' ||
|
||||
apiVersion > allVersions[version].latestApiVersion
|
||||
) {
|
||||
allVersions[version].latestApiVersion = apiVersion
|
||||
}
|
||||
}
|
||||
})
|
||||
// Adds the calendar date (or api versions) to the allVersions object
|
||||
const apiVersions = JSON.parse(fs.readFileSync(REST_DATA_META_FILE, 'utf8'))['api-versions']
|
||||
Object.keys(apiVersions).forEach((key) => {
|
||||
const docsVersion = getDocsVersion(key)
|
||||
allVersions[docsVersion].apiVersions.push(...apiVersions[key].sort())
|
||||
allVersions[docsVersion].latestApiVersion = apiVersions[key].pop()
|
||||
})
|
||||
|
||||
export const allVersionKeys = Object.keys(allVersions)
|
||||
export const allVersionShortnames = Object.fromEntries(
|
||||
|
||||
Reference in New Issue
Block a user