Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3672 from newrelic/add_mdx_verify_script
add mdx verification script
- Loading branch information
Showing
2 changed files
with
36 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const mdx = require('@mdx-js/mdx'); | ||
const fs = require('fs'); | ||
const glob = require('glob'); | ||
|
||
const readFile = async (filePath) => { | ||
try { | ||
console.log(`reading ${filePath}`); | ||
const mdxText = fs.readFileSync(filePath, 'utf8'); | ||
const jsx = mdx.sync(mdxText); | ||
} catch (exception) { | ||
console.log(JSON.stringify(exception, null, 4)); | ||
return filePath; | ||
} | ||
}; | ||
|
||
const main = async () => { | ||
let filePaths = process.argv.slice(2); | ||
|
||
if (filePaths.length === 0) { | ||
// if user did not supply paths, default to all | ||
filePaths = glob.sync( | ||
`${__dirname}/../src{/content/**/*.mdx,/i18n/content/**/*.mdx}` | ||
); | ||
} | ||
|
||
const allResults = await Promise.all(filePaths.map(readFile)); | ||
const results = allResults.filter(Boolean); | ||
|
||
console.log(results); | ||
console.log(`Failed file count: ${results.length}`); | ||
}; | ||
|
||
main(); |