import {
  writeError,
  writeTrace
} from "./chunk-ONQDU5G7.js";
import {
  getOutputFile,
  init_esm_shims
} from "./chunk-C7FSMRRA.js";

// src/generators/json-schema.ts
init_esm_shims();
import { writeFile } from "node:fs/promises";
function generateJsonSchemaFile(schema, file, config) {
  try {
    const jsonSchema = getOutputFile(file, "json");
    writeTrace(`Writing JSON schema file ${jsonSchema}`, config);
    return writeFile(jsonSchema, JSON.stringify(schema, null, 2));
  } catch (error) {
    writeError(
      `Error writing JSON schema file for ${file.name}

Error:
${error?.message ? error.message : JSON.stringify(error)}${error?.stack ? `
Stack Trace: ${error.stack}` : ""}

Parsed schema:
${JSON.stringify(schema)}
`,
      config
    );
    throw error;
  }
}

export {
  generateJsonSchemaFile
};
