mirror of
https://github.com/ivan-94/obsidian-plugin-manushelf.git
synced 2026-07-22 08:33:19 +00:00
32 lines
979 B
JavaScript
32 lines
979 B
JavaScript
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
import Ajv2020 from "ajv/dist/2020.js";
|
|
import standaloneCode from "ajv/dist/standalone/index.js";
|
|
|
|
async function loadSchema(path) {
|
|
return JSON.parse(await readFile(path, "utf8"));
|
|
}
|
|
|
|
const ajv = new Ajv2020({
|
|
allErrors: true,
|
|
strict: false,
|
|
code: { esm: true, source: true },
|
|
});
|
|
|
|
const [librarySchema, bookManifestSchema] = await Promise.all([
|
|
loadSchema("docs/specs/schemas/library.schema.json"),
|
|
loadSchema("docs/specs/schemas/book-manifest.schema.json"),
|
|
]);
|
|
|
|
ajv.addSchema(librarySchema, "library-config");
|
|
ajv.addSchema(bookManifestSchema, "book-manifest");
|
|
const generated = standaloneCode(ajv, {
|
|
validateLibraryConfig: "library-config",
|
|
validateBookManifest: "book-manifest",
|
|
});
|
|
|
|
await mkdir("src/generated", { recursive: true });
|
|
await writeFile(
|
|
"src/generated/validators.ts",
|
|
`// Generated from docs/specs/schemas. Do not edit by hand.\n// @ts-nocheck\n${generated}`,
|
|
"utf8",
|
|
);
|