typebox-cli
Version:
CLI tool for various TypeBox and JSON Schema operations
19 lines • 701 B
JavaScript
import path from "node:path";
import { createJiti } from "jiti";
import { TypeGuard } from "@sinclair/typebox";
export function loadSchemaInModule(modulePath, jiti = createJiti(process.cwd(), {
extensions: [".ts", ".js"],
interopDefault: true,
})) {
const absolutePath = path.resolve(process.cwd(), modulePath);
const module = jiti(absolutePath);
if (typeof module !== "object" || module === null) {
throw new Error("Module must be an object");
}
return {
types: Object.entries(module)
.filter((exp) => TypeGuard.IsSchema(exp[1]))
.map(([$id, schema]) => ({ $id, ...schema })),
};
}
//# sourceMappingURL=loadSchemaInModule.js.map