UNPKG

boats

Version:

Beautiful Open / Async Template System - Write less yaml with BOATS and Nunjucks.

28 lines (27 loc) 1.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = default_1; const tslib_1 = require("tslib"); const upath_1 = tslib_1.__importDefault(require("upath")); const fs_extra_1 = tslib_1.__importDefault(require("fs-extra")); const js_yaml_1 = tslib_1.__importDefault(require("js-yaml")); const deepmerge_1 = tslib_1.__importDefault(require("deepmerge")); function default_1() { const tplGlobals = this.env.globals; let main = {}; for (const key in arguments) { if (arguments.hasOwnProperty(key)) { // eslint-disable-next-line prefer-rest-params const injectPath = upath_1.default.join(upath_1.default.dirname(tplGlobals.currentFilePointer), arguments[key]); if (!fs_extra_1.default.pathExistsSync(injectPath)) { throw new Error('Path not found when trying to make optional: ' + injectPath); } const content = js_yaml_1.default.load(fs_extra_1.default.readFileSync(injectPath, 'utf-8')); if (content && content['type'] !== 'object') { throw new TypeError('Referenced item must be an object: ' + injectPath); } main = (0, deepmerge_1.default)(main, content); } } return js_yaml_1.default.dump(main); }