| | import path from 'path' |
| | import walk from 'walk-sync' |
| | import { readFile } from 'fs/promises' |
| |
|
| | import { |
| | updateContentDirectory, |
| | convertVersionsToFrontmatter, |
| | } from '../../../automated-pipelines/lib/update-markdown' |
| | import { getDocsVersion } from '@/versions/lib/all-versions' |
| | import { REST_DATA_DIR, REST_SCHEMA_FILENAME } from '../../lib/index' |
| | import { deprecated } from '@/versions/lib/enterprise-server-releases' |
| |
|
| | type RestVersions = { |
| | [category: string]: { |
| | [subcategory: string]: { |
| | versions: string[] |
| | } |
| | } |
| | } |
| |
|
| | type MarkdownUpdate = { |
| | data: { |
| | title: string |
| | shortTitle: string |
| | intro: string |
| | versions: any |
| | [key: string]: any |
| | } |
| | content: string |
| | } |
| |
|
| | type MarkdownUpdates = { |
| | [filepath: string]: MarkdownUpdate |
| | } |
| |
|
| | const { frontmatterDefaults, targetDirectory, indexOrder } = JSON.parse( |
| | await readFile('src/rest/lib/config.json', 'utf-8'), |
| | ) |
| |
|
| | export async function updateRestFiles() { |
| | const restVersions = await getDataFrontmatter(REST_DATA_DIR, REST_SCHEMA_FILENAME) |
| | const restMarkdownContent = await getMarkdownContent(restVersions) |
| | await updateContentDirectory({ |
| | targetDirectory, |
| | sourceContent: restMarkdownContent, |
| | frontmatter: frontmatterDefaults, |
| | indexOrder, |
| | }) |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | export function getGHESVersionFromFilepath(filePath: string): string | null { |
| | |
| | const normalizedPath = filePath.replace(/\\/g, '/') |
| | const pathParts = normalizedPath.split('/') |
| | const ghesDir = pathParts.find((part) => part.startsWith('ghes-')) |
| |
|
| | if (!ghesDir) { |
| | return null |
| | } |
| |
|
| | |
| | const versionMatch = ghesDir.match(/^ghes-(\d+\.\d+)/) |
| | return versionMatch ? versionMatch[1] : null |
| | } |
| |
|
| | |
| | |
| | async function getDataFrontmatter( |
| | dataDirectory: string, |
| | schemaFilename: string, |
| | ): Promise<RestVersions> { |
| | const fileList = walk(dataDirectory, { includeBasePath: true }) |
| | .filter((file) => path.basename(file) === schemaFilename) |
| | |
| | |
| | |
| | .filter((file) => { |
| | const ghesVersion = getGHESVersionFromFilepath(file) |
| |
|
| | |
| | if (!ghesVersion) { |
| | return true |
| | } |
| |
|
| | |
| | return !deprecated.includes(ghesVersion) |
| | }) |
| |
|
| | const restVersions: RestVersions = {} |
| |
|
| | for (const file of fileList) { |
| | const data = JSON.parse(await readFile(file, 'utf-8')) |
| | const docsVersionName = getDocsVersion(path.basename(path.dirname(file))) |
| | for (const category of Object.keys(data)) { |
| | |
| | const subcategories = Object.keys(data[category]) |
| | for (const subcategory of subcategories) { |
| | if (!restVersions[category]) { |
| | restVersions[category] = {} |
| | } |
| | if (!restVersions[category][subcategory]) { |
| | restVersions[category][subcategory] = { |
| | versions: [docsVersionName], |
| | } |
| | } else if (!restVersions[category][subcategory].versions.includes(docsVersionName)) { |
| | restVersions[category][subcategory].versions.push(docsVersionName) |
| | } |
| | } |
| | } |
| | } |
| | return restVersions |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | async function getMarkdownContent(versions: RestVersions): Promise<MarkdownUpdates> { |
| | const markdownUpdates: MarkdownUpdates = {} |
| |
|
| | for (const [category, subcategoryObject] of Object.entries(versions)) { |
| | const subcategories = Object.keys(subcategoryObject) |
| | |
| | for (const subcategory of subcategories) { |
| | const filepath = path.join('content/rest', category, `${subcategory}.md`) |
| | |
| | |
| | |
| | |
| | |
| | markdownUpdates[filepath] = { |
| | data: { |
| | title: 'TODOCS', |
| | shortTitle: 'TODOCS', |
| | intro: 'TODOCS', |
| | versions: await convertVersionsToFrontmatter(versions[category][subcategory].versions), |
| | ...frontmatterDefaults, |
| | }, |
| | content: '', |
| | } |
| | } |
| | } |
| |
|
| | return markdownUpdates |
| | } |
| |
|