"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = writeHtml;

var _handlebars = _interopRequireDefault(require("handlebars"));

var _fs = _interopRequireDefault(require("fs"));

var _templates = require("./templates");

var _utils = require("../../utils");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
 * Compile HTML template and write it to HTML file
 * @param {object} data keys to parse to Handlbars for templating
 * @param {string} file path to write file to
 */
async function writeHtml(data, file) {
  data.pkgInfo = (0, _utils.getPkgInfo)();
  const html = await (0, _templates.loadTemplate)('index');

  const template = _handlebars.default.compile(html);

  const htmlResult = template(data); // write HTML file

  _fs.default.writeFile(file, htmlResult, error => {
    if (error) {
      throw error;
    }

    return file;
  });
}