map rendered strings to template token source

This commit is contained in:
Gregor Lohaus
2026-05-22 09:05:02 +02:00
parent 3110eefcbd
commit bda6e8cc40
4 changed files with 255 additions and 13 deletions

View File

@@ -1,6 +1,8 @@
import { z } from "zod"
import { parse, type TemplateVariable } from "./parser"
import { renderDir } from "./render"
import { renderDir, type RenderOptions } from "./render"
export type { RenderOptions, ReverseMapFile, ReverseMapManifest, ReverseMapToken } from "./render"
interface Stringable {
toString: () => string
@@ -85,9 +87,9 @@ export const initRenderer = (dirPath: string) => {
const createRenderer = <S extends z.ZodType>(userSchema: S) => {
validateSchemaMatchesTemplates(userSchema, variables)
return (targetPath: string, context: z.infer<S>) => {
return (targetPath: string, context: z.infer<S>, options?: RenderOptions) => {
userSchema.parse(context)
renderDir(dirPath, targetPath, context as Record<string, unknown>)
renderDir(dirPath, targetPath, context as Record<string, unknown>, options)
}
}