mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
32 lines
968 B
TypeScript
32 lines
968 B
TypeScript
import * as fs from 'fs';
|
|
import * as Handlebars from 'handlebars';
|
|
|
|
/**
|
|
* Read and compile the Handlebars template.
|
|
* @param filePath
|
|
*/
|
|
export function readHandlebarsTemplate(filePath: string): Handlebars.TemplateDelegate {
|
|
if (fs.existsSync(filePath)) {
|
|
try {
|
|
const template = fs
|
|
.readFileSync(filePath, 'utf8')
|
|
.toString()
|
|
.trim();
|
|
return Handlebars.compile(template, {
|
|
strict: true,
|
|
noEscape: true,
|
|
preventIndent: true,
|
|
ignoreStandalone: true,
|
|
knownHelpersOnly: true,
|
|
knownHelpers: {
|
|
indent: true,
|
|
eq: true,
|
|
},
|
|
});
|
|
} catch (e) {
|
|
throw new Error(`Could not compile Handlebar template: "${filePath}"`);
|
|
}
|
|
}
|
|
throw new Error(`Could not find Handlebar template: "${filePath}"`);
|
|
}
|