-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathvalidate.js
More file actions
37 lines (32 loc) · 1.03 KB
/
Copy pathvalidate.js
File metadata and controls
37 lines (32 loc) · 1.03 KB
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
const Validator = require('jsonschema').Validator;
const schema = require('./schema.json');
const glob = require('glob');
const v = new Validator();
const libraries = [];
const directory = './libraries/**/*';
glob(directory, { nodir: true }, (err, files) => {
let errors = [];
if (err) {
console.log('Error reading files', { err });
process.exit(-1);
} else {
files.forEach((file) => {
// Check if file has .json extension
if (file.indexOf('.json') === -1) {
errors.push(`File ${file} does not end with .json`);
return;
}
const repo = require(file);
const result = v.validate(repo, schema);
if (result.errors.length > 0) {
errors = errors.concat(result.errors);
}
});
}
if (errors.length > 0) {
console.log('Errors with validation', { errors });
process.exit(-1);
}
console.log('No validation errors found');
process.exit(0);
});