UNPKG

@veecode-platform/safira-cli

Version:

Generate a microservice project from your spec.

53 lines (52 loc) 2.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.InstallVkpr = void 0; const tslib_1 = require("tslib"); const pre_install_1 = require("./pre-install"); const properties = tslib_1.__importStar(require("../properties.json")); const vkpr_repository_1 = require("./vkpr-repository"); const version_utils_1 = require("../utils/version-utils"); const command_execute_1 = require("../command/command-execute"); const json_utils_1 = require("../utils/json-utils"); const file_system_utils_1 = require("../utils/file-system-utils"); class InstallVkpr { constructor() { } async install() { new pre_install_1.PreInstall().checkCommand(); const currentVersion = await this.getCurrentVersion(); const latestVersion = await this.getLatestVersion(); if (latestVersion === InstallVkpr.defaultVersion) { throw new Error("Could not get the latest version of VKPR"); } if (version_utils_1.VersionUtils.compareVersions(currentVersion, latestVersion) === -1) { if (currentVersion === InstallVkpr.defaultVersion) { await command_execute_1.CommandExecute.instance.exec("curl -fsSL https://get.vkpr.net/ | bash"); return; } await command_execute_1.CommandExecute.instance.exec(`${properties.vkpr.command} upgrade`); } } static get instance() { if (!this._instance) { this._instance = new this(); } return this._instance; } async getCurrentVersion() { try { const repositoriesFilePath = file_system_utils_1.FileSystemUtils.buildPath(file_system_utils_1.FileSystemUtils.getOsUserHome(), ".rit", "repos", "repositories.json"); const repoFile = json_utils_1.JsonUtils.loadJsonFile(repositoriesFilePath); const version = repoFile.find(repo => repo.url === "https://github.com/vertigobr/vkpr-cli").version.match(/\d+\.\d+\.\d+/); if (version) return version[0].toString(); } catch { } return InstallVkpr.defaultVersion; } async getLatestVersion() { const release = await vkpr_repository_1.VkprRepositoryService.instance.getReleaseLatest(); return release?.tag_name?.match(/\d+\.\d+\.\d+/)[0] || InstallVkpr.defaultVersion; } } exports.InstallVkpr = InstallVkpr; InstallVkpr.defaultVersion = "0.0.0";