diff --git a/.github/workflows/pr-validation.yml b/.github/workflows/pr-validation.yml index fcb2781..c49bd68 100644 --- a/.github/workflows/pr-validation.yml +++ b/.github/workflows/pr-validation.yml @@ -8,7 +8,7 @@ on: - '.github/workflows/**' jobs: - validate-mdx: + mdx-validation: runs-on: ubuntu-latest steps: - name: Checkout repo @@ -21,27 +21,10 @@ jobs: cache: 'npm' - name: MDX validation dependencies - run: npm install --save-dev @mdx-js/mdx @mdx-js/loader + run: npm install --save-dev @mdx-js/mdx @mdx-js/loader glob - name: Validate MDX files - run: | - # Find and validate all MDX files in the docs directory - find docs -name "*.mdx" -type f | while read file; do - echo "Validating: $file" - node -e " - const fs = require('fs'); - const { compile } = require('@mdx-js/mdx'); - - try { - const content = fs.readFileSync('$file', 'utf8'); - compile(content, { jsx: true }); - console.log('āœ… $file - Valid MDX'); - } catch (error) { - console.error('āŒ $file - MDX Error:', error.message); - process.exit(1); - } - " - done + run: node scripts/validate-mdx.js - name: Check for broken links run: | diff --git a/package.json b/package.json index 1825063..12a518a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,8 @@ { + "type": "module", "devDependencies": { "@mdx-js/loader": "^3.1.0", - "@mdx-js/mdx": "^3.1.0" + "@mdx-js/mdx": "^3.1.0", + "glob": "^10.3.10" } } diff --git a/scripts/validate-mdx.js b/scripts/validate-mdx.js new file mode 100644 index 0000000..e34d3de --- /dev/null +++ b/scripts/validate-mdx.js @@ -0,0 +1,28 @@ +import fs from 'fs'; +import { compile } from '@mdx-js/mdx'; +import { glob } from 'glob'; + +async function validateMDX() { + try { + const mdxFiles = await glob('docs/**/*.mdx'); + + for (const file of mdxFiles) { + console.log(`Validating: ${file}`); + try { + const content = fs.readFileSync(file, 'utf8'); + await compile(content, { jsx: true }); + console.log(`āœ… ${file} - Valid MDX`); + } catch (error) { + console.error(`āŒ ${file} - MDX Error:`, error.message); + process.exit(1); + } + } + + console.log(`\nšŸŽ‰ All ${mdxFiles.length} MDX files are valid!`); + } catch (error) { + console.error('āŒ Validation failed:', error.message); + process.exit(1); + } +} + +validateMDX(); \ No newline at end of file