import fs from "fs-extra" ; import { HandlebarsWithAmfHelpers } from "./" ; /**
 * Holds a template and renders the template with the given data
 */ export class Template { content : string ; param path param handlebars constructor ( public path , public handlebars = HandlebarsWithAmfHelpers ) { try { this . content = fs . readFileSync ( path , "utf8" ) ; } catch ( error ) { error . message = `Error initializing template: ${ error . message }` ; throw error ; } if ( ! this . content ) { throw new Error ( `Invalid template content: ${ this . content }` ) ; } } param context param destination async render ( context , destination ) { try { await fs . outputFile ( destination , this . handlebars . compile ( this . content ) ( context , { allowProtoPropertiesByDefault : true , allowProtoMethodsByDefault : true , } ) ) ; } catch ( error ) { error . message = `Error rendering template: ${ error . message }` ; throw error ; } } }