diff --git a/package.json b/package.json index 56af59e..34cfe04 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,8 @@ "build:exports": "rollup --config rollup.config.ts --configPlugin typescript", "clean": "rm -rf ./dist/ && rm -rf ./streamdeck/", "lint": "eslint . --ext .ts --max-warnings 0", - "preversion": "npm run build && npm run lint" + "preversion": "npm run lint", + "version": "npm run build" }, "repository": { "type": "git", diff --git a/scripts/build.ts b/scripts/build.ts index e6970e1..8102d5e 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -1,41 +1,39 @@ -/* eslint-disable no-useless-escape */ import type { JSONSchema7 } from "json-schema"; import { existsSync, mkdirSync, writeFileSync } from "node:fs"; import { join } from "node:path"; import { createGenerator } from "ts-json-schema-generator"; +import pkg from "../package.json"; import { customKeywordTransformer } from "./transformers/custom-keywords"; import { versionManifests } from "./transformers/version-manifests"; -// Create a generator so we're able to produce multiple schemas. -const generator = createGenerator({ - extraTags: ["errorMessage", "imageDimensions", "filePath"], - path: join(__dirname, "../src/streamdeck/plugins/index.ts"), - skipTypeCheck: true, - tsconfig: join(__dirname, "../tsconfig.json") -}); - // Prepare the output directory. const outputDir = join(__dirname, "../streamdeck/plugins"); if (!existsSync(outputDir)) { mkdirSync(outputDir, { recursive: true }); } -generateAndWriteSchema("Manifest", versionManifests); -generateAndWriteSchema("Layout"); +generateAndWriteSchema("Manifest", [customKeywordTransformer, versionManifests]); +generateAndWriteSchema("Layout", [customKeywordTransformer]); /** * Generates the JSON schema for the specified TypeScript `type`, and writes it locally to `{type}.json`. * @param type TypeScript type whose schema should be generated. - * @param transform Optional function used to transform the schema. + * @param transformers Optional function used to transform the schema. */ -function generateAndWriteSchema(type: string, transform?: (schema: JSONSchema7) => void): void { - const schema = generator.createSchema(type); - if (transform) { - transform(schema); - } +function generateAndWriteSchema(type: string, transformers?: ((schema: JSONSchema7) => void)[]): void { + // Build the generator. + const path = join(__dirname, "../src/streamdeck/plugins/index.ts"); + const generator = createGenerator({ + extraTags: ["errorMessage", "imageDimensions", "filePath"], + path, + skipTypeCheck: true, + schemaId: `${pkg.name}/streamdeck/plugins/${type.toLowerCase()}@${pkg.version}`, + tsconfig: join(__dirname, "../tsconfig.json") + }); - // Apply the custom keyword transformer to all schemas - customKeywordTransformer(schema); + // Generate the schema, and apply the transformers. + const schema = generator.createSchema(type); + transformers?.forEach((t) => t(schema)); // Determine the output path, and serialize the schema. const outputPath = join(outputDir, `${type.toLowerCase()}.json`);