UNPKG

@topgroup/diginext

Version:

A BUILD SERVER & CLI to deploy apps to any Kubernetes clusters.

84 lines (83 loc) 4.15 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.askForProjectAndApp = void 0; const inquirer_1 = __importDefault(require("inquirer")); const lodash_1 = require("lodash"); const app_config_1 = require("../../app.config"); const plugins_1 = require("../../plugins"); const create_or_select_app_1 = require("./create-or-select-app"); const create_or_select_project_1 = require("./create-or-select-project"); const askForProjectAndApp = async (dir, options) => { const { DB } = await Promise.resolve().then(() => __importStar(require("../api/DB"))); if (app_config_1.isServerMode) throw new Error(`Unable to use "askForProjectAndApp()" in SERVER mode.`); const currentGitData = await (0, plugins_1.getCurrentGitRepoData)(dir || (options === null || options === void 0 ? void 0 : options.targetDirectory)); if (options === null || options === void 0 ? void 0 : options.isDebugging) console.log("askForProjectAndApp() > currentGitData :>> ", currentGitData); let apps = await DB.find("app", { "git.repoSSH": currentGitData.repoSSH }, { populate: ["project", "owner", "workspace"], isDebugging: options === null || options === void 0 ? void 0 : options.isDebugging }); let app; let project; // no apps found -> create or select one: if ((0, lodash_1.isEmpty)(apps)) { // try to find apps with deprecated "dx.json" file: const oldAppConfig = (0, plugins_1.getAppConfig)(); if (oldAppConfig) { app = await DB.findOne("app", { slug: oldAppConfig.slug }, { populate: ["project", "owner", "workspace"], ignorable: true }); if (app) { project = await DB.findOne("project", { slug: oldAppConfig.project }, { ignorable: true }); if (!(0, lodash_1.isEmpty)(project)) return { project, app }; } } // if still no results -> create or select one: project = await (0, create_or_select_project_1.createOrSelectProject)(options); app = await (0, create_or_select_app_1.createOrSelectApp)(project.slug, options); return { project, app }; } // if there are only 1 app with this git repo -> select it: if (!apps || apps.length === 1) { app = apps[0]; project = (0, lodash_1.isEmpty)(app.project) ? await (0, create_or_select_project_1.createOrSelectProject)(options) : app.project; return { project, app }; } // if there are more than 1 app with this git repo -> select one: const { selectedApp } = await inquirer_1.default.prompt({ type: "list", name: "selectedApp", message: `Select app:`, default: apps[0], choices: apps.map((_app, i) => { return { name: `[${i + 1}] ${_app.name} (${_app.slug})`, value: _app }; }), }); app = selectedApp; project = app.project; return { project, app }; }; exports.askForProjectAndApp = askForProjectAndApp;