import Handlebars from 'handlebars' ; import { resolve , isAbsolute } from 'path' ; import { readFile } from './fs-async' ; import { getHexCodepoint } from './codepoints' ; export const TEMPLATE_HELPERS = { codepoint : getHexCodepoint } ; export type CompileOptions = { helpers ? : { [ key ] : ( ... args : any [ ] ) => string ; } ; } ; export const renderTemplate = async ( templatePath , context , options = { } ) => { const absoluteTemplatePath = isAbsolute ( templatePath ) ? templatePath : resolve ( process . cwd ( ) , templatePath ) ; const template = await readFile ( absoluteTemplatePath , 'utf8' ) ; return Handlebars . compile ( template ) ( context , { ... options , helpers : { ... TEMPLATE_HELPERS , ... ( options . helpers || { } ) } } ) ; } ;