forked from adobe/xdm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
lint.js
46 lines (33 loc) · 1.6 KB
/
lint.js
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const $ = require("shelljs");
const fs = require('fs');
const schemas = $.find("schemas").filter(name => { return name.match(/.*\.schema\.json$/)});
const extensions = $.find("extensions").filter(name => { return name.match(/.*\.schema\.json$/)});
const examples = $.find("schemas").filter(name => { return name.match(/.*\.example\.[0-9]+\.json$/)});
const invalids = $.find("schemas").filter(name => { return name.match(/.*\.invalid\.[0-9]+\.json$/)});
const package = JSON.parse(fs.readFileSync('package.json', 'utf8'));
let failures = 0;
if (schemas.length!=package.config.schemas) {
console.error("Found " + schemas.length + " schemas but expected " + package.config.schemas + " for XDM version " + package.version);
console.error("Open package.json and increase the minor version number then update the config.schemas parameter to " + schemas.length);
failures++;
}
const all = schemas.concat(extensions, examples, invalids);
all.forEach(json => {
const pretty = $.exec("json-beautify -s 2 -f " + json, {silent: true}).stdout;
const orig = $.exec("cat " + json, {silent: true});
if (pretty!=orig) {
failures++;
console.warn(json + " is not pretty. Fixing." );
$.exec("json-beautify -r -s 2 -f " + json, {silent: true})
}
});
schemas.forEach(schema => {
const result = $.exec("ajv validate --errors=text --all-errors -s meta.schema.json -d " + schema, {silent: true} );
if (result.code!=0) {
failures++;
console.error("Schema " + schema + " does not validate against meta.schema.json");
console.error(result.stderr);
console.error(result.stdout);
}
});
$.exit(failures);