blob: 26451cf91f478f6c25deb6f27daa7172264e981f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
import handlebars from "handlebars";
import fs from "fs";
/**
* Information for processing a template file into the output file
*/
export interface Template {
inputFile: string;
outputFile: string;
context: Record<string, string>;
data?: string;
}
/**
* Process input file and produce file at given output location
*/
export default async (_template: Template): Promise<Template> => {
const buffer = await fs.promises.readFile(_template.inputFile, "utf-8");
const translate = handlebars.compile(buffer);
const template = {
..._template,
data: translate(_template.context),
};
await fs.promises.writeFile(template.outputFile, template.data);
return template;
};
|