UNPKG

barbells

Version:

[//]: # ( ns__file unit: standard, comp: README.md )

32 lines (31 loc) 1.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.loadFileTemplate = void 0; const expandNsbbreviations_1 = require("./expandNsbbreviations"); // const {fileMatchesCustomFileFilter} = require('magicalstrings').fileMatchesCustomFileFilter // import {Configuration} from 'magicalstrings' const minimatch = require('minimatch'); const fs = require('fs-extra'); async function loadFileTemplate(pathString, Handlebars, fileFilter, noFileInfo = false) { // noFileInfo suppresses generation of a file info tag at the beginning of the template. let template = ''; try { template = await fs.readFile(pathString, 'utf-8'); if (!noFileInfo && fileFilter && minimatch(pathString.slice(0, -4), fileFilter, { dot: true, matchBase: true })) { template = '{{nsFile}}\n' + template; // add file info automatically. } template = expandNsbbreviations_1.expandNsAbbreviations(template); } catch (error) { // eslint-disable-next-line no-console console.error(error); throw new Error(`error finding the file ${pathString}. It may be that the template location is faulty, or that the template is not correctly specified: ${error}`); } return Handlebars.compile(template); } exports.loadFileTemplate = loadFileTemplate;