Check for orphaned assets in CI (#24074)
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user