UNPKG

@bitblit/epsilon

Version:

Tiny adapter to simplify building API gateway Lambda APIS

38 lines 1.61 kB
"use strict"; /* Functions to combine a set of yaml files */ Object.defineProperty(exports, "__esModule", { value: true }); var fs = require("fs"); var require_ratchet_1 = require("@bitblit/ratchet/dist/common/require-ratchet"); var yaml = require("js-yaml"); var logger_1 = require("@bitblit/ratchet/dist/common/logger"); var YamlCombiner = /** @class */ (function () { function YamlCombiner() { } YamlCombiner.combine = function (files, inRootPath) { if (inRootPath === void 0) { inRootPath = []; } require_ratchet_1.RequireRatchet.notNullOrUndefined(files, 'Files argument'); require_ratchet_1.RequireRatchet.true(files.length > 0, 'Files argument larger than 0'); require_ratchet_1.RequireRatchet.notNullOrUndefined(inRootPath, 'Root path argument'); logger_1.Logger.info('Processing %d files into output', files.length); var allElements = {}; for (var i = 0; i < files.length; i++) { var fileContents = fs.readFileSync(files[i]).toString(); var openApi = yaml.load(fileContents); allElements = Object.assign(allElements, openApi); } var rootPath = Object.assign([], inRootPath); while (rootPath.length > 0) { var next = {}; next[rootPath[rootPath.length - 1]] = allElements; rootPath.splice(rootPath.length - 1, 1); allElements = next; } var rval = yaml.dump(allElements); return rval; }; return YamlCombiner; }()); exports.YamlCombiner = YamlCombiner; //# sourceMappingURL=yaml-combiner.js.map