Skip to content

Commit

Permalink
Merge pull request #3672 from newrelic/add_mdx_verify_script
Browse files Browse the repository at this point in the history
add mdx verification script
  • Loading branch information
MoonlightKomorebi committed Aug 27, 2021
2 parents 0f108b1 + d6fa1b3 commit 5d9a400
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -41,8 +41,8 @@
"hast-util-select": "^4.0.2",
"hast-util-to-mdast": "^7.1.3",
"jest": "^26.6.3",
"jest-when": "^3.3.1",
"jest-emotion": "^10.0.32",
"jest-when": "^3.3.1",
"jsdom": "^16.5.0",
"lodash": "^4.17.21",
"parse-link-header": "^1.0.1",
Expand Down Expand Up @@ -151,7 +151,8 @@
"postinstall": "patch-package",
"extract-i18n": "i18next",
"get-translated-files": "node scripts/actions/add-files-to-translation-queue.js",
"check-for-outdated-translations": "node scripts/actions/check-for-outdated-translations.js"
"check-for-outdated-translations": "node scripts/actions/check-for-outdated-translations.js",
"verify-mdx": "node scripts/verify_mdx.js"
},
"husky": {
"hooks": {
Expand Down
33 changes: 33 additions & 0 deletions scripts/verify_mdx.js
@@ -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();

0 comments on commit 5d9a400

Please sign in to comment.