-
Notifications
You must be signed in to change notification settings - Fork 244
Expand file tree
/
Copy pathbuild.js
More file actions
28 lines (25 loc) · 942 Bytes
/
build.js
File metadata and controls
28 lines (25 loc) · 942 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const fs = require("fs")
const path = require("path")
const Ajv = require('ajv').default;
const standaloneCode = require("ajv/dist/standalone").default
const addFormats = require('ajv-formats').default;
const schema = require("../../docs/CVE_Record_Format_bundled.json")
function reduceSchema(o) {
for(prop in o) {
if(typeof(o[prop])=='object') {
reduceSchema(o[prop])
} else if (prop == "description" && typeof(o[prop])=='string') {
delete o[prop]
} else if (prop == "title" && typeof(o[prop])=='string') {
delete o[prop]
}
}
return o;
}
var rSchema = reduceSchema(schema);
const ajv = new Ajv({code: {source: true, optimize: 10}})
addFormats(ajv);
const validate = ajv.compile(rSchema)
let moduleCode = standaloneCode(ajv, validate)
// Now you can write the module code to file
fs.writeFileSync(path.join(__dirname+'/dist', "cve5validator.js"), moduleCode)