@veecode-platform/safira-cli
Version:
Generate a microservice project from your spec.
59 lines (58 loc) • 3.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const core_1 = require("@oclif/core");
const insomnia_utils_1 = require("../../insomnia/insomnia-utils");
const file_system_utils_1 = require("../../utils/file-system-utils");
const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
const constants_1 = require("../../utils/commands/constants");
const color_1 = tslib_1.__importDefault(require("@oclif/color"));
const exit_codes_1 = require("../../command/exit-codes");
const safiraColors = tslib_1.__importStar(require("../../colors.json"));
class InsomniaExport extends core_1.Command {
async run() {
const { args, flags } = await this.parse(InsomniaExport);
const path = file_system_utils_1.FileSystemUtils.getCurrentPath();
if (!insomnia_utils_1.InsomniaUtils.instance.isInsomniaWorkspace(path)) {
console.log(color_1.default.bold.red("Insomnia workspace not found in this project!"));
process.exit(exit_codes_1.ExitCode.noSuchFileOrDirectory);
}
const exportSpecAnswer = await inquirer_1.default.prompt([
{
type: "input",
name: "export-spec-path",
message: "What is the folder where you want to export the spec?",
default: ".",
validate: (value) => file_system_utils_1.FileSystemUtils.exists(value) ? true : "Please enter a valid folder",
},
]);
let exportSpecPath = (flags["export-spec-path"] || exportSpecAnswer["export-spec-path"]);
if (exportSpecPath) {
exportSpecPath = file_system_utils_1.FileSystemUtils.fullPath(exportSpecPath);
console.log("Export Spec Path:", exportSpecPath);
const insoPath = file_system_utils_1.FileSystemUtils.buildPath(path, ".insomnia");
const projectName = file_system_utils_1.FileSystemUtils.getHighFolderFromPath(file_system_utils_1.FileSystemUtils.getCurrentPath());
const finalSpecPath = file_system_utils_1.FileSystemUtils.buildPath(exportSpecPath, `${projectName}-openapi.yaml`);
const overwriteSpecAnswer = await inquirer_1.default.prompt([
{
when: file_system_utils_1.FileSystemUtils.exists(finalSpecPath),
type: "list",
name: "overwrite-spec",
message: "Do you want to overwrite the spec?",
choices: constants_1.yesNoList,
},
]);
if (!file_system_utils_1.FileSystemUtils.exists(finalSpecPath) || overwriteSpecAnswer["overwrite-spec"] === "yes") {
await insomnia_utils_1.InsomniaUtils.instance.exportInsomniaSpec(finalSpecPath, path, insomnia_utils_1.InsomniaUtils.instance.getListSpecName(insoPath)[0]);
const neonGreen = color_1.default.hex(safiraColors["neon-green"]);
console.log(neonGreen.bold(`Spec exported to ${finalSpecPath}`));
}
}
}
}
exports.default = InsomniaExport;
InsomniaExport.description = "Export your insomnia spec";
InsomniaExport.flags = {
help: core_1.Flags.help({ char: "h" }),
};
InsomniaExport.args = [];