diff --git a/types.d.ts b/types.d.ts index e77f6b2..cab98e9 100644 --- a/types.d.ts +++ b/types.d.ts @@ -1,4 +1,4 @@ -type SupportedSourceDomains = "youtube"; +type SupportedSourceDomains = "youtube" | "crunchyroll" | "disney"; type SupportedVideoTypes = "music video" | "television episode" | "movie" | "other" export interface ScriptInfo { diff --git a/validator.ts b/validator.ts index ce5e43c..d8cb03c 100644 --- a/validator.ts +++ b/validator.ts @@ -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"));