UNPKG

@veecode-platform/safira-cli

Version:

Generate a microservice project from your spec.

32 lines (31 loc) 1.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.YamlUtils = void 0; const tslib_1 = require("tslib"); const YAML = tslib_1.__importStar(require("yaml")); const file_system_utils_1 = require("./file-system-utils"); class YamlUtils { static loadYamlFile(filePath) { if (!filePath) { throw new Error("input a file"); } if (!file_system_utils_1.FileSystemUtils.exists(filePath)) { throw new Error(`file not found, ${filePath}`); } const yamlData = file_system_utils_1.FileSystemUtils.loadFile(filePath); return this.parse(yamlData); } static parse(yamlData) { return YAML.parse(yamlData); } static stringify(yamlObject) { return YAML.stringify(yamlObject, { simpleKeys: true }); } static writeFile(filePath, yamlObject) { file_system_utils_1.FileSystemUtils.writeFile(filePath, this.stringify(yamlObject)); } static isYamlFile(filePath) { return (filePath?.toLowerCase().match(/\.[()almy|]+$/i) || []).length > 0; } } exports.YamlUtils = YamlUtils;