diff --git a/src/automated-pipelines/lib/update-markdown.js b/src/automated-pipelines/lib/update-markdown.js index 84ed7a35a7..b10c6cf449 100644 --- a/src/automated-pipelines/lib/update-markdown.js +++ b/src/automated-pipelines/lib/update-markdown.js @@ -16,12 +16,12 @@ export const MARKDOWN_COMMENT = // Main entrypoint into this module. This function adds, removes, and updates // versions frontmatter in all directories under the targetDirectory. -export async function updateContentDirectory( +export async function updateContentDirectory({ targetDirectory, sourceContent, frontmatter, - indexOrder -) { + indexOrder, +}) { const sourceFiles = Object.keys(sourceContent) await createDirectory(targetDirectory) await removeMarkdownFiles(targetDirectory, sourceFiles, frontmatter.autogenerated) diff --git a/src/automated-pipelines/tests/update-content-directory.js b/src/automated-pipelines/tests/update-content-directory.js index 05b1b6f768..16859a1fd3 100644 --- a/src/automated-pipelines/tests/update-content-directory.js +++ b/src/automated-pipelines/tests/update-content-directory.js @@ -73,18 +73,19 @@ describe('automated content directory updates', () => { // Rewrites the content directory in the operating system's // temp directory. - await updateContentDirectory( + await updateContentDirectory({ targetDirectory, - contentDataFullPath, - { + sourceContent: contentDataFullPath, + frontmatter: { autogenerated: 'rest', }, - indexOrder - ) + indexOrder, + }) }) afterAll(async () => { await rm(tempDirectory, { recursive: true, force: true }) + delete process.env.TEST_OS_ROOT_DIR }) test('expected files and directories are removed', async () => { diff --git a/src/codeql-cli/scripts/sync.js b/src/codeql-cli/scripts/sync.js index cb9779a605..6528ec1dfd 100755 --- a/src/codeql-cli/scripts/sync.js +++ b/src/codeql-cli/scripts/sync.js @@ -43,7 +43,11 @@ async function main() { cliMarkdownContents[targetFilename] = { data: sourceData, content: finalSourceContent } } // Begin updating Markdown files in the content directory - await updateContentDirectory(targetDirectory, cliMarkdownContents, frontmatterDefaults) + await updateContentDirectory({ + targetDirectory, + sourceContent: cliMarkdownContents, + frontmatter: frontmatterDefaults, + }) } // Separates out steps that need to be done before the sync can begin diff --git a/src/rest/scripts/utils/update-markdown.js b/src/rest/scripts/utils/update-markdown.js index 9e456f6219..923d48e1b8 100644 --- a/src/rest/scripts/utils/update-markdown.js +++ b/src/rest/scripts/utils/update-markdown.js @@ -17,7 +17,11 @@ const { frontmatterDefaults, targetDirectory } = JSON.parse( export async function updateRestFiles() { const restVersions = await getDataFrontmatter(REST_DATA_DIR, REST_SCHEMA_FILENAME) const restMarkdownContent = await getMarkdownContent(restVersions) - await updateContentDirectory(targetDirectory, restMarkdownContent, frontmatterDefaults) + await updateContentDirectory({ + targetDirectory, + sourceContent: restMarkdownContent, + frontmatter: frontmatterDefaults, + }) } // Reads data files from the directory provided and returns a @@ -80,10 +84,12 @@ async function getMarkdownContent(versions) { for (const category of Object.keys(versions)) { const subcategories = Object.keys(versions[category]) - // When there is only a single subcategory, the Markdown file - // will be at the root of the content/rest directory. The - // file path will be content/rest/.md - if (subcategories.length === 1) { + // When there is only a single subcategory and the name + // matches the category, this is an override due to a + // subcategory not being defined. In this case, + // the markdown file will be in the content/rest directory. + // The file path will be content/rest/.md + if (subcategories.length === 1 && category === subcategories[0]) { // this will be a file in the root of the rest directory const filepath = path.join('content/rest', `${category}.md`) markdownUpdates[filepath] = {