1 | const Ajv = require('ajv')
|
2 | const {schema} = require('./schema')
|
3 | const {extglobFormat} = require('./format-extglob')
|
4 |
|
5 | const ajv = new Ajv({format: 'full'})
|
6 | ajv.addFormat('extglob', extglobFormat)
|
7 | ajv.addSchema(schema)
|
8 |
|
9 | module.exports.validate =
|
10 | function validate (json) {
|
11 | const validity = ajv.validate('/Manifest', json)
|
12 | if (validity === true) {
|
13 | return true
|
14 | } else {
|
15 | const last = ajv.errors.pop()
|
16 | const message = `${last.dataPath} ${last.message} ${last.schemaPath}`
|
17 | throw new Error(message)
|
18 | }
|
19 | }
|