From 5bdc31057df274a4e33196ec4d1b112240c11372 Mon Sep 17 00:00:00 2001 From: Jakob Niggel Date: Fri, 18 Feb 2022 15:38:54 +0100 Subject: [PATCH] fix: catch ts-json-schema error and pretty print --- packages/cli/src/helper/generateSchema.ts | 14 ++++++++++++++ packages/cli/src/helper/index.ts | 5 ++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/helper/generateSchema.ts b/packages/cli/src/helper/generateSchema.ts index 3e168454..20a70b6f 100644 --- a/packages/cli/src/helper/generateSchema.ts +++ b/packages/cli/src/helper/generateSchema.ts @@ -1,5 +1,6 @@ import $RefParser from '@apidevtools/json-schema-ref-parser'; import * as ts from 'ts-json-schema-generator'; +import { log } from '../log.js'; interface GenerateSchemaOptions { removeDateTime: boolean; } @@ -40,6 +41,19 @@ export class GenerateGlobalSchema { return ''; } + if (e.diagnostics) { + e.diagnostics.forEach( + (element: { messageText: string; file: { fileName: string } }) => { + log({ + component: 'cli', + warning: element.messageText, + details: element.file.fileName, + }); + }, + ); + return ''; + } + throw e; } } diff --git a/packages/cli/src/helper/index.ts b/packages/cli/src/helper/index.ts index 01764df4..f2e6e5bf 100644 --- a/packages/cli/src/helper/index.ts +++ b/packages/cli/src/helper/index.ts @@ -14,7 +14,10 @@ export async function writeControllerJson() { export async function writeSchemaJson() { const config = await getConfig(); - const schema = await generateSchema(config.entry, { removeDateTime: false }); + let schema = await generateSchema(config.entry, { removeDateTime: false }); + if (!schema) { + schema = '{}'; + } writeFile(join(config.outdir, 'flux-schema.json'), schema); }