-
Notifications
You must be signed in to change notification settings - Fork 0
/
validator.ts
31 lines (27 loc) · 917 Bytes
/
validator.ts
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
import Ajv from "ajv";
import schema from "./ScriptData.json";
import path from "path";
import fs from "fs";
const validateDirectory = (dir: string) => {
const files = fs.readdirSync(dir);
files.forEach((f) => {
const file_path = path.join(dir, f);
const stats = fs.statSync(file_path);
if(stats.isDirectory()){
validateDirectory(file_path);
return;
}
const contents = JSON.parse(fs.readFileSync(path.join(dir, f)).toString());
if(contents.scripts[0].author === ""){
console.log("Unspecified author in file", f)
}
const isValid = validator(contents);
if(!isValid){
console.log("Error with file", f);
console.log(validator.errors);
}
});
}
const ajv = new Ajv();
const validator = ajv.compile(schema);
validateDirectory(path.join(__dirname, "transcripts"));