UNPKG

mili

Version:

Scaffolding with continuous control over the development of the project.

38 lines (37 loc) 1.82 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import * as fs from 'fs-extra'; import * as path from 'path'; import * as Handlebars from 'handlebars'; import * as R from 'ramda'; import * as HandlebarsRamdaHelpers from 'handlebars-ramda-helpers'; HandlebarsRamdaHelpers.register(Handlebars); Handlebars.registerHelper('isEmpty', function (value) { return R.isEmpty(value); }); Handlebars.registerHelper('equals', function (lvalue, rvalue) { return R.equals(lvalue, rvalue); }); Handlebars.registerHelper('head', function (arr) { return R.head(arr); }); export const compile = function (dist, src, filepath, resource, options) { return __awaiter(this, void 0, void 0, function* () { const encoding = options.encoding; const srcfilepath = path.join(src, filepath); filepath = filepath.replace(/\.(hbs|handlebars)$/, ''); const source = yield fs.readFile(srcfilepath, { encoding }); const template = Handlebars.compile(source); const view = R.fromPairs(Array.from(resource.entries())); const result = template(view); yield fs.writeFile(path.join(src, filepath), result); return filepath; }); };