UNPKG

@theme-json/validate

Version:
29 lines (28 loc) 875 B
/** * External dependencies */ import Avj from 'ajv-draft-04'; import axios from 'axios'; /** * Internal dependencies */ import { errorsText } from './utils.mjs'; let schema; export const after = async (themeJson, config) => { const schemaChecker = new Avj({ allErrors: true, strict: true, allowMatchingProperties: true, }); const schemaVersion = config['wpVersion'] === 'trunk' ? 'trunk' : `wp/${config['wpVersion']}`; if (!schema) { schema = await axios.get(`https://schemas.wp.org/${schemaVersion}/theme.json`); } const validate = schemaChecker.compile(schema.data); const valid = validate(themeJson); if (!valid) { console.log('\n‼️ Invalid theme.json\n'); console.log(errorsText(validate === null || validate === void 0 ? void 0 : validate.errors)); } return themeJson; };