UNPKG

@veecode-platform/safira-cli

Version:

Generate a microservice project from your spec.

49 lines (48 loc) 2.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.InsomniaUtils = void 0; const file_system_utils_1 = require("../utils/file-system-utils"); const yaml_utils_1 = require("../utils/yaml-utils"); const export_spec_1 = require("./export-spec"); class InsomniaUtils { constructor() { } isInsomniaWorkspace(workspace) { workspace = this._getInsomniaPath(workspace); return file_system_utils_1.FileSystemUtils.exists(file_system_utils_1.FileSystemUtils.buildPath(workspace, "Workspace")); } getListSpecName(workspace) { workspace = this._getInsomniaPath(file_system_utils_1.FileSystemUtils.fullPath(workspace)); if (this.isInsomniaWorkspace(workspace)) { const specPath = file_system_utils_1.FileSystemUtils.buildPath(workspace, "ApiSpec"); return file_system_utils_1.FileSystemUtils.readDir(specPath) .map(spec => file_system_utils_1.FileSystemUtils.buildPath(specPath, spec)) .map(spec => yaml_utils_1.YamlUtils.loadYamlFile(spec)) .map(spec => spec.fileName); } return []; } _getInsomniaPath(workspace) { if (file_system_utils_1.FileSystemUtils.getHighFolderFromPath(workspace) !== ".insomnia") { return file_system_utils_1.FileSystemUtils.buildPath(workspace, ".insomnia"); } return workspace; } async exportInsomniaSpec(insoSpecExported, insoWorkPath, specName) { if (insoWorkPath && specName) { if (file_system_utils_1.FileSystemUtils.isFile(insoWorkPath)) { await export_spec_1.ExportOpenapiSpec.instance.exportSpecInsomniaV4(insoWorkPath, specName, insoSpecExported); } else { console.log("Exporting openapi from Insomnia Workspace"); await export_spec_1.ExportOpenapiSpec.instance.exportSpecWorkspace(insoWorkPath, specName, insoSpecExported); } } } static get instance() { if (!this._instance) { this._instance = new this(); } return this._instance; } } exports.InsomniaUtils = InsomniaUtils;