(directory: string)
| 31 | } |
| 32 | |
| 33 | export async function generateModels(directory: string) { |
| 34 | const result: Record<string, ModelMetadata> = {}; |
| 35 | if (!existsSync(directory)) return result; |
| 36 | |
| 37 | for await (const modelPath of new Bun.Glob("**/*.toml").scan({ |
| 38 | cwd: directory, |
| 39 | absolute: true, |
| 40 | followSymlinks: true, |
| 41 | })) { |
| 42 | const modelID = path.relative(directory, modelPath).split(path.sep).join("/").slice(0, -5); |
| 43 | const toml = await import(modelPath, { |
| 44 | with: { |
| 45 | type: "toml", |
| 46 | }, |
| 47 | }).then((mod) => mod.default); |
| 48 | toml.id = modelID; |
| 49 | |
| 50 | const model = ModelMetadata.safeParse(toml); |
| 51 | if (!model.success) { |
| 52 | model.error.cause = { modelPath, toml }; |
| 53 | throw model.error; |
| 54 | } |
| 55 | result[modelID] = model.data; |
| 56 | } |
| 57 | |
| 58 | return result; |
| 59 | } |
| 60 | |
| 61 | export async function generate(directory: string) { |
| 62 | const modelsDirectory = path.join(path.dirname(directory), "models"); |
no outgoing calls
no test coverage detected