diff --git a/scripts/make_schemas.ts b/scripts/make_schemas.ts index 93189593..7a418103 100644 --- a/scripts/make_schemas.ts +++ b/scripts/make_schemas.ts @@ -1,6 +1,11 @@ -//import { createGenerator } from "npm:ts-json-schema-generator"; +import * as path from "https://deno.land/std/path/mod.ts"; +import { DenoDir } from "https://deno.land/x/deno_cache@0.4.1/mod.ts"; import { exec } from "https://deno.land/x/exec/mod.ts"; +import { sleep } from "https://deno.land/x/sleep/mod.ts"; +/** + * An array of objects containing the path to the TypeScript file, the type to generate a schema for, and the path to the tsconfig.json file. + */ const configs = [ { path: "./npm/src/style.ts", @@ -36,9 +41,24 @@ for (const config of configs) { `typescript-json-schema --no-type-check ${config.path} ${config.type} --out ${schemaFileName}`; console.log(`[schemas] Generating ${schemaFileName}...`); - // console.log(command); exec(command); + + sleep(1000000); + + if (config.type === "Style" && Deno.stat(schemaFileName)) { + console.log("[schemas] Fixing CSL style schema ..."); + // why am I getting a file not found error here? + const schema = JSON.parse(Deno.readTextFileSync(path.resolve(schemaFileName))); + // modify this property to workaround upstream bug + delete schema.properties.templates.$ref; + schema.properties.templates.type = "object"; + schema.properties.templates.patternProperties = { + "": { type: "#/definitions/InputReference" } + }; + + Deno.writeTextFileSync(schemaFileName, JSON.stringify(schema)); + } } console.log("[schemas] Complete!");