diff --git a/bin/validate-json.js b/bin/validate-json.js new file mode 100755 index 0000000..71b783e --- /dev/null +++ b/bin/validate-json.js @@ -0,0 +1,23 @@ +#!/usr/bin/env node +const fs = require('fs'); + +const files = process.argv.slice(2); +let hadError = false; + +files.forEach((file) => { + const content = fs.readFileSync(file, 'utf8'); + const regex = /```json\n([\s\S]*?)```/gm; + let match; + while ((match = regex.exec(content)) !== null) { + try { + JSON.parse(match[1]); + } catch (err) { + console.error(`Invalid JSON in ${file}: ${err.message}`); + hadError = true; + } + } +}); + +if (hadError) { + process.exit(1); +} diff --git a/package.json b/package.json index 62385b2..b1c655a 100644 --- a/package.json +++ b/package.json @@ -6,9 +6,10 @@ "private": true, "scripts": { "validate": "node_modules/.bin/mdv ./spec.md ./README.md ./build/markdown/*.md", + "validate:json": "./bin/validate-json.js ./spec.md", "lint": "./node_modules/.bin/markdownlint ./spec.md ./README.md ./build/markdown/*.md", "build": "./bin/build.sh", - "test": "npm run build && npm run validate && npm run lint" + "test": "npm run build && npm run validate && npm run lint && npm run validate:json" }, "repository": { "type": "git",