Created
March 27, 2024 21:15
-
-
Save antonkalik/92457b267d899322313e0724bb32994f to your computer and use it in GitHub Desktop.
Generate Template Helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import path from 'path'; | |
import fs from 'fs'; | |
import handlebars from 'handlebars'; | |
export const generateTemplate = <T>(name: string, props: T): string => { | |
const templatePath = path.join(__dirname, '..', 'src/templates', `${name}.hbs`); | |
const templateSource = fs.readFileSync(templatePath, 'utf8'); | |
const template = handlebars.compile(templateSource); | |
return template(props); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment