1
0
mirror of synced 2025-12-23 03:44:00 -05:00

Check for orphaned assets in CI (#24074)

This commit is contained in:
Peter Bengtsson
2022-01-05 11:26:45 -05:00
committed by GitHub
parent 3a8c8c4ba3
commit 26d2c5438a
2 changed files with 34 additions and 4 deletions

View File

@@ -20,7 +20,7 @@ const EXCEPTIONS = new Set([
])
program
.description('Print all images that are in ./assets/ but not found in any markdown')
.description('Print all images that are in ./assets/ but not found in any source files')
.option('-e, --exit', 'Exit script by count of orphans (useful for CI)')
.option('-v, --verbose', 'Verbose outputs')
.option('--json', 'Output in JSON format')
@@ -83,8 +83,8 @@ async function main(opts) {
verbose && console.log(`${allImages.size.toLocaleString()} images found in total.`)
for (const markdownFile of sourceFiles) {
const content = fs.readFileSync(markdownFile, 'utf-8')
for (const sourceFile of sourceFiles) {
const content = fs.readFileSync(sourceFile, 'utf-8')
for (const imagePath of allImages) {
const needle = imagePath.split(path.sep).slice(-2).join('/')
if (content.includes(needle) || EXCEPTIONS.has(imagePath)) {
@@ -94,7 +94,7 @@ async function main(opts) {
}
if (verbose && allImages.size) {
console.log('The following files are not mentioned anywhere in any Markdown file')
console.log('The following files are not mentioned anywhere in any source file')
}
if (json) {
console.log(JSON.stringify([...allImages], undefined, 2))