UNPKG

@veecode-platform/safira-cli

Version:

Generate a microservice project from your spec.

125 lines (124 loc) 4.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OktetoClient = void 0; const okteto_download_1 = require("./okteto-download"); const child_process_1 = require("child_process"); const safira_utils_1 = require("../safira-project/safira-utils"); const safira_exception_1 = require("../exception/safira-exception"); var OktetoCommands; (function (OktetoCommands) { OktetoCommands["UP"] = "up"; OktetoCommands["DOWN"] = "down"; OktetoCommands["CONTEXT"] = "context"; OktetoCommands["CONTEXT_DELETE"] = "context delete"; OktetoCommands["CONTEXT_LIST"] = "context list"; OktetoCommands["CONTEXT_SHOW"] = "context show"; OktetoCommands["CONTEXT_USE"] = "context use"; })(OktetoCommands || (OktetoCommands = {})); class OktetoClient { constructor() { this._oktetoDownloader = new okteto_download_1.OktetoDownloadProvider(); } async up({ build, context, file, namespace, pull, remote, reset, loglevel }) { const flags = []; if (context) flags.push(`--context=${context}`); if (file) flags.push(`--file=${file}`); if (loglevel) flags.push(`--loglevel=${loglevel}`); if (namespace) flags.push(`--namespace=${namespace}`); if (remote) flags.push(`--remote=${remote}`); if (build) flags.push("--build"); if (pull) flags.push("--pull"); if (reset) flags.push("--reset"); await this._executeCommand(OktetoCommands.UP, flags); } async down({ namespace, volumes, context, file }) { const flags = []; if (namespace) flags.push(`--namespace=${namespace}`); if (volumes) flags.push("--volumes"); if (context) flags.push(`--context=${context}`); if (file) flags.push(`--file=${file}`); await this._executeCommand(OktetoCommands.DOWN, flags); } async destroy({ namespace, volumes, context, file, dependencies, forceDestroy, name, noBash }) { const flags = []; if (context) flags.push(`--context=${context}`); if (dependencies) flags.push(`--dependencies=${dependencies}`); if (file) flags.push(`--file=${file}`); if (forceDestroy) flags.push("--forceDestroy"); if (name) flags.push(`--name=${name}`); if (namespace) flags.push(`--namespace=${namespace}`); if (noBash) flags.push("--noBash"); if (volumes) flags.push("--volumes"); await this._executeCommand(OktetoCommands.DOWN, flags); } async contextDelete() { const flags = []; await this._executeCommand(OktetoCommands.CONTEXT_DELETE, flags); } async contextList(output) { const flags = []; if (output) flags.push(`--output=${output}`); await this._executeCommand(OktetoCommands.CONTEXT_LIST, flags); } async contextShow(output) { const flags = []; if (output) flags.push(`--output=${output}`); await this._executeCommand(OktetoCommands.CONTEXT_SHOW, flags); } async contextUse({ builder, namespace, token }) { const flags = []; if (builder) flags.push(`--builder=${builder}`); if (namespace) flags.push(`--namespace=${namespace}`); if (token) flags.push(`--token=${context}`); await this._executeCommand(OktetoCommands.CONTEXT_USE, flags); } async context({ builder, namespace, token }) { const flags = []; if (builder) flags.push(`--builder=${builder}`); if (namespace) flags.push(`--namespace=${namespace}`); if (token) flags.push(`--token=${context}`); await this._executeCommand(OktetoCommands.CONTEXT, flags); } async _executeCommand(command, flags) { if (safira_utils_1.SafiraUtils.isSafiraProject()) { const bin = await this._oktetoDownloader.download(); this._execute(bin, command, flags ?? []); return; } throw new safira_exception_1.SafiraProjectNotFoundException("Not a safira project"); } async _execute(binaryPath, command, flags) { const shell = (0, child_process_1.spawn)(binaryPath, [command, ...flags], { stdio: "inherit" }); shell.on("close", code => { }); } } exports.OktetoClient = OktetoClient;