UNPKG

@reliverse/rse-sdk

Version:

@reliverse/rse-sdk without cli. @reliverse/rse-sdk allows you to create new plugins for @reliverse/rse CLI, interact with reliverse.org, and even extend your own CLI functionality (you may also try @reliverse/dler-sdk for this case).

24 lines (23 loc) 920 B
import fs from "@reliverse/relifso"; import { relinka } from "@reliverse/relinka"; import handlebars from "handlebars"; import path from "node:path"; export async function processTemplate(srcPath, destPath, context) { try { const templateContent = await fs.readFile(srcPath, "utf-8"); const template = handlebars.compile(templateContent); const processedContent = template(context); await fs.ensureDir(path.dirname(destPath)); await fs.writeFile(destPath, processedContent); } catch (error) { relinka("error", `Error processing template ${srcPath}:`, error); throw new Error(`Failed to process template ${srcPath}`); } } handlebars.registerHelper("eq", (a, b) => a === b); handlebars.registerHelper("and", (a, b) => a && b); handlebars.registerHelper("or", (a, b) => a || b); handlebars.registerHelper( "includes", (array, value) => Array.isArray(array) && array.includes(value) );