// LICENSE : MIT "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.readFileFromPath = readFileFromPath; exports.getTemplateContent = getTemplateContent; var _options = require("./options.js"); var fs = require("fs"); var logger = require("winston-color"); /** * Sunc file read with path check * @param {string} path * @return {string} */ function readFileFromPath(path) { var content = void 0; try { content = fs.readFileSync(path, "utf8"); } catch (err) { if (err.code === "ENOENT") { logger.warn("Error: file not found: " + path); return "Error: file not found: " + path; } else { throw err; } } return content; } /** * Load template from template label * @param {object} kvMap * @return {string} */ function getTemplateContent(kvMap) { var t = kvMap.template; var dt = _options.defaultBookOptionsMap.template; var tPath = _options.defaultTemplateMap[t]; var dtPath = _options.defaultTemplateMap[dt]; var isTemplateDefault = t === dt; var isTemplatePath = tPath === undefined; var p = void 0; // No template option. if (isTemplateDefault) { p = dtPath; } else if (isTemplatePath) { // Template option is a path. p = t; } else { // Template option one of template/ directory. p = tPath || dtPath; } return readFileFromPath(p); } //# sourceMappingURL=template.js.map