-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
test.js
64 lines (55 loc) · 1.52 KB
/
test.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const Ajv = require('ajv');
const fs = require('fs');
const yaml = require('js-yaml');
const ajv = new Ajv({
strictTypes: false,
});
// Add support for intellij html description
ajv.addKeyword('x-intellij-html-description');
const schemas = [
{
pattern: /NodeTypes.*\.yaml$/,
schemaFile: './NodeTypes.Schema.json',
},
{
pattern: /Caches.*\.yaml$/,
schemaFile: './Caches.Schema.json',
},
{
pattern: /Version.*\.yaml$/,
schemaFile: './NodeMigration.Schema.json',
},
{
pattern: /Routes.*\.yaml$/,
schemaFile: './Routes.Schema.json',
},
{
pattern: /Settings.*\.yaml$/,
schemaFile: './NodeTypes.Presets.Schema.json',
},
].map(sd => {
const schema = JSON.parse(fs.readFileSync(sd.schemaFile, { encoding: 'utf8', flag: 'r' }));
const validate = ajv.compile(schema);
return {
...sd,
schema,
validate,
};
});
const files = fs.readdirSync('./examples');
let hasError = false;
for (const file of files) {
const fileContent = fs.readFileSync(`./examples/${file}`, { encoding: 'utf8', flag: 'r' });
const data = yaml.load(fileContent);
const schema = schemas.find(sd => sd.pattern.test(file));
if (!schema) {
console.warn('Could not validate %s, no matching schema found', file);
continue;
}
const valid = schema.validate(data);
if (!valid) {
console.error(schema.validate.errors);
hasError = true;
}
}
process.exit(hasError ? 1 : 0);