Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

chore(schemas): fix schema generation bug #147

Merged
merged 1 commit into from
May 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 60 additions & 39 deletions scripts/make_schemas.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,65 @@
//import { createGenerator } from "npm:ts-json-schema-generator";
import console from "https://deno.land/std@0.177.0/node/console.ts";
import { exec } from "https://deno.land/x/exec/mod.ts";

const configs = [
{
path: "./npm/src/style.ts",
type: "Style",
tsconfig: "tsconfig.json",
},

{
path: "./npm/src/reference.ts",
type: "InputReference",
tsconfig: "tsconfig.json",
},
{
path: "./npm/src/bibliography.ts",
type: "InputBibliography",
tsconfig: "tsconfig.json",
},
{
path: "./npm/src/citation.ts",
type: "Citation",
tsconfig: "tsconfig.json",
},
];

console.log("");

for (const config of configs) {
// need to run on npm code, so make sure to run the make_npm.ts script first
const schemaFileName = `./schemas/csl-${
config["type"].toLowerCase()
}-schema.json`;
const command =
`typescript-json-schema --no-type-check ${config.path} ${config.type} --out ${schemaFileName}`;

console.log(`[schemas] Generating ${schemaFileName}...`);
// console.log(command);

exec(command);
function generateSchemas() {
console.log("");

const configs = [
{
path: "./npm/src/style.ts",
type: "Style",
tsconfig: "tsconfig.json",
},

{
path: "./npm/src/reference.ts",
type: "InputReference",
tsconfig: "tsconfig.json",
},
{
path: "./npm/src/bibliography.ts",
type: "InputBibliography",
tsconfig: "tsconfig.json",
},
{
path: "./npm/src/citation.ts",
type: "Citation",
tsconfig: "tsconfig.json",
},
];

for (const config of configs) {
// need to run on npm code, so make sure to run the make_npm.ts script first
const schemaFileName = `./schemas/csl-${
config["type"].toLowerCase()
}-schema.json`;
const command =
`typescript-json-schema --no-type-check ${config.path} ${config.type} --out ${schemaFileName}`;

console.log(`[schemas] Generating ${schemaFileName} ...`);

exec(command);
}
}

function fixSchemas() {
console.log("[schemas] Fixing style schema ...");
const schemaFileName = `./schemas/csl-style-schema.json`;
const schema = JSON.parse(Deno.readTextFileSync(schemaFileName));

// why doesn't this work???
schema.properties.templates = {
type: "object",
patternProperties: {
"": { type: "#/definitions/InputReference" },
},
};

const schemaString = JSON.stringify(schema, null, 2);
Deno.writeTextFileSync(schemaFileName, schemaString);
}

generateSchemas();
fixSchemas();

console.log("[schemas] Complete!");