UNPKG

@veecode-platform/safira-cli

Version:

Generate a microservice project from your spec.

40 lines (39 loc) 2.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ExportOpenapiSpec = void 0; const file_system_utils_1 = require("../utils/file-system-utils"); const inso_client_1 = require("./inso-client"); const string_utils_1 = require("../utils/string-utils"); const command_execute_1 = require("../command/command-execute"); const spec_discovery_exception_1 = require("../exception/spec-discovery-exception"); class ExportOpenapiSpec { constructor() { } async exportSpecWorkspace(workDir, specName, outputFile) { if (string_utils_1.StringUtils.isNullOrEmpty(specName)) throw new Error("specName is required"); const insoBin = await new inso_client_1.InsomniaClient().loadCli(); const command = `${insoBin} export spec "${specName}" --workingDir "${file_system_utils_1.FileSystemUtils.fullPath(workDir)}" --output "${file_system_utils_1.FileSystemUtils.fullPath(outputFile)}"`; await command_execute_1.CommandExecute.instance.exec(command, false); if (!file_system_utils_1.FileSystemUtils.exists(file_system_utils_1.FileSystemUtils.fullPath(outputFile))) throw new spec_discovery_exception_1.SpecDiscoveryNotFoundException("Openapi could not be extracted from insomnia workspace"); } async generateKongForKubernetesWorkspace(workDir, specName, outputFile) { const insoBin = await new inso_client_1.InsomniaClient().loadCli(); await command_execute_1.CommandExecute.instance.exec(`${insoBin} generate config "${specName}" --type kubernetes --workingDir "${file_system_utils_1.FileSystemUtils.fullPath(workDir)}" --output "${file_system_utils_1.FileSystemUtils.fullPath(outputFile)}"`, false); } async exportSpecInsomniaV4(insomniaV4File, specName, outputFile) { const insoBin = await new inso_client_1.InsomniaClient().loadCli(); await command_execute_1.CommandExecute.instance.exec(`${insoBin} export spec "${specName}" --src "${file_system_utils_1.FileSystemUtils.fullPath(insomniaV4File)}" --output "${file_system_utils_1.FileSystemUtils.fullPath(outputFile)}"`, false); } async generateKongForKubernetesInsomniaV4(insomniaV4File, specName, outputFile) { const insoBin = await new inso_client_1.InsomniaClient().loadCli(); await command_execute_1.CommandExecute.instance.exec(`${insoBin} generate config "${specName}" --type kubernetes --src "${file_system_utils_1.FileSystemUtils.fullPath(insomniaV4File)}" --output "${file_system_utils_1.FileSystemUtils.fullPath(outputFile)}"`, false); } static get instance() { if (!this._instance) { this._instance = new this(); } return this._instance; } } exports.ExportOpenapiSpec = ExportOpenapiSpec;