barbells
Version:
[//]: # ( ns__file unit: standard, comp: README.md )
30 lines (29 loc) • 1.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerHelpers = void 0;
const path = require('path');
const fs = require('fs-extra');
function registerHelper(path, name, Handlebars) {
// Require helper
const functionDef = require(path)[name];
// Register helper
Handlebars.registerHelper(name, functionDef);
}
async function registerHelpers(dir, Handlebars) {
if (!await fs.pathExists(dir))
return;
const helpers = await fs.readdir(dir);
await Promise.all(helpers.map(async (fileName) => {
const filePath = `${dir}/${fileName}`;
const fileType = path.parse(filePath).ext;
if (fs.lstatSync(filePath).isDirectory()) {
await registerHelpers(filePath, Handlebars);
return;
}
if (fileType === '.ts') {
const helperName = path.parse(filePath).name;
registerHelper(filePath, helperName, Handlebars);
}
}));
}
exports.registerHelpers = registerHelpers;