Skip to content

Commit

Permalink
Fix validator
Browse files Browse the repository at this point in the history
  • Loading branch information
julianna-langston committed Oct 18, 2024
1 parent 1b70365 commit f3df166
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type SupportedSourceDomains = "youtube";
type SupportedSourceDomains = "youtube" | "crunchyroll" | "disney";
type SupportedVideoTypes = "music video" | "television episode" | "movie" | "other"

export interface ScriptInfo {
Expand Down
38 changes: 24 additions & 14 deletions validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,29 @@ 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);
const directory = path.join(__dirname, "transcripts");
const files = fs.readdirSync(directory);
files.forEach((f) => {
const contents = JSON.parse(fs.readFileSync(path.join(directory, 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);
}
});
validateDirectory(path.join(__dirname, "transcripts"));

0 comments on commit f3df166

Please sign in to comment.