import { PinionContext, Callable, getCallable } from '../core' import { WriteFileOptions, promptWriteFile, addTrace } from './helpers' /** * Renders a template to a file. * * @param template The template to render * @param target The target file handle, usually provided by `to()` * @returns The generator context */ export const renderTemplate = ( template: Callable, target: Callable, options: Partial = {} ) => async (ctx: T) => { const fileName = await getCallable(target, ctx) const content = await getCallable(template, ctx) const result = await promptWriteFile(fileName, content, ctx, options) return addTrace(result, 'renderTemplate', { fileName, content }) }