Skip to content

Commit

Permalink
Logg all duplicate snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler-hoffman committed Feb 5, 2024
1 parent 61545a4 commit 5126943
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions docs/docusaurus/scripts/remark-named-snippets/snippet.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,24 @@ const htmlparser2 = require('htmlparser2')
*/
function constructSnippetMap(dirs) {
const snippets = parseSourceDirectories(dirs)
const duplicateNames = []

const snippetMap = {}
for (const snippet of snippets) {
const name = snippet.name
if (name in snippetMap) {
throw new Error(
`A snippet named ${name} has already been defined elsewhere`
)
duplicateNames.push(name)
}
delete snippet.name // Remove duplicate filename to clean up stdout
snippetMap[name] = snippet
}
if (duplicateNames.length > 0) {
console.error("Duplicate snippet names found:")
console.error(duplicateNames.map((name) => ` ${name}`).join('\n'))
throw new Error(
`${duplicateNames.length} duplicate snippet names found`
)
}

return snippetMap
}
Expand Down

0 comments on commit 5126943

Please sign in to comment.