UNPKG

@veecode-platform/safira-cli

Version:

Generate a microservice project from your spec.

56 lines (55 loc) 3.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const core_1 = require("@oclif/core"); const operation_1 = require("../../../configmap/operation"); const file_system_utils_1 = require("../../../utils/file-system-utils"); const safira_settings_1 = require("../../../safira-project/safira-settings"); const safira_base_command_1 = require("../../../command-base/safira-base-command"); const inquirer_1 = tslib_1.__importDefault(require("inquirer")); const cache_manager_1 = require("../../../cache/cache-manager"); const string_validator_1 = require("../../../validator/string-validator"); const color_1 = tslib_1.__importDefault(require("@oclif/color")); class ProjectConfigmapNew extends safira_base_command_1.SafiraBaseCommand { async run() { const { args, flags } = await this.parse(ProjectConfigmapNew); const currentPath = file_system_utils_1.FileSystemUtils.getCurrentPath(); this.checkIfSafiraProject(); const namespaces = cache_manager_1.CacheManager.instance.getCache(cache_manager_1.CacheName.kubernetesNamespace); const answers = await inquirer_1.default.prompt([ { when: !flags.namespace && namespaces.length > 0, type: "list", name: "namespace-list", message: "Select k8s namespace", choices: [...namespaces, { name: "Input other value", value: "other" }], }, { when: answers => !flags.namespace && (namespaces.length === 0 || answers["namespace-list"] === "other"), type: "input", name: "namespace", message: "Input k8s namespace:", default: "default", validate: (value) => string_validator_1.StringValidator.notEmpty(value) ? true : "k8s namespace required", }, ]); if (answers.namespace || flags.namespace) cache_manager_1.CacheManager.instance.addItem(cache_manager_1.CacheName.kubernetesNamespace, answers.namespace || flags.namespace); const settings = safira_settings_1.SafiraSettings.instance(currentPath).loadSettingsFile(); const propertiesFile = file_system_utils_1.FileSystemUtils.buildPath(currentPath, "src", "main", "resources", "application.properties"); const filePath = operation_1.ConfigMapOperation.instance.create(propertiesFile, settings.project.name, flags.namespace || answers.namespace || answers["namespace-list"]); this.log(color_1.default.green(`${color_1.default.bold("Update properties before apply:")} ${filePath}`)); } } exports.default = ProjectConfigmapNew; ProjectConfigmapNew.hidden = true; ProjectConfigmapNew.description = "Generate new k8s configmap"; ProjectConfigmapNew.examples = [ "<%= config.bin %> <%= command.id %>", "<%= config.bin %> <%= command.id %> --namespace production", "<%= config.bin %> <%= command.id %> -n production", ]; ProjectConfigmapNew.flags = { namespace: core_1.Flags.string({ char: "n", description: "namespace of the configmap" }), }; ProjectConfigmapNew.args = [];