UNPKG

@bitblit/ratchet-epsilon-common

Version:

Tiny adapter to simplify building API gateway Lambda APIS

28 lines 1.22 kB
import fs from 'fs'; import { RequireRatchet } from '@bitblit/ratchet-common/lang/require-ratchet'; import yaml from 'js-yaml'; import { Logger } from '@bitblit/ratchet-common/logger/logger'; export class YamlCombiner { static combine(files, inRootPath = []) { RequireRatchet.notNullOrUndefined(files, 'Files argument'); RequireRatchet.true(files.length > 0, 'Files argument larger than 0'); RequireRatchet.notNullOrUndefined(inRootPath, 'Root path argument'); Logger.info('Processing %d files into output', files.length); let allElements = {}; for (const fName of files) { const fileContents = fs.readFileSync(fName).toString(); const openApi = yaml.load(fileContents); allElements = Object.assign(allElements, openApi); } const rootPath = Object.assign([], inRootPath); while (rootPath.length > 0) { const next = {}; next[rootPath[rootPath.length - 1]] = allElements; rootPath.splice(rootPath.length - 1, 1); allElements = next; } const rval = yaml.dump(allElements); return rval; } } //# sourceMappingURL=yaml-combiner.js.map