From d32c3b2be2f17744214ebf95a74dc4c86a926d1c Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Sun, 5 Oct 2025 01:33:03 -0600 Subject: [PATCH] feat: enhance app deployment command with environment selection - Added environmentId flag to the AppDeploy command for specifying the environment. - Implemented interactive prompts for selecting project, environment, and application if flags are not provided. - Updated type definitions to include Application and Environment types for better type safety. - Improved error handling for cases with no available environments or applications. --- src/commands/app/deploy.ts | 49 ++++++++++++++++++++++++++++++------ src/commands/authenticate.ts | 4 --- src/utils/shared.ts | 23 +++++++++++++++++ 3 files changed, 64 insertions(+), 12 deletions(-) diff --git a/src/commands/app/deploy.ts b/src/commands/app/deploy.ts index 66206bb..479f7f0 100644 --- a/src/commands/app/deploy.ts +++ b/src/commands/app/deploy.ts @@ -1,7 +1,7 @@ import { Command, Flags } from "@oclif/core"; import { readAuthConfig } from "../../utils/utils.js"; import chalk from "chalk"; -import { getProject, getProjects } from "../../utils/shared.js"; +import { getProject, getProjects, type Application } from "../../utils/shared.js"; import inquirer from "inquirer"; import type { Answers } from "./create.js"; import axios from "axios"; @@ -26,6 +26,11 @@ export default class AppDeploy extends Command { description: 'ID of the project', required: false, }), + environmentId: Flags.string({ + char: 'e', + description: 'ID of the environment', + required: false, + }), skipConfirm: Flags.boolean({ char: 'y', description: 'Skip confirmation prompt', @@ -36,13 +41,17 @@ export default class AppDeploy extends Command { public async run(): Promise { const auth = await readAuthConfig(this); const { flags } = await this.parse(AppDeploy); - let { projectId, applicationId } = flags; + let { projectId, applicationId, environmentId } = flags; // Modo interactivo si no se proporcionan los flags necesarios - if (!projectId || !applicationId) { + if (!projectId || !applicationId || !environmentId) { console.log(chalk.blue.bold("\n Listing all Projects \n")); const projects = await getProjects(auth, this); + let selectedProject; + let selectedEnvironment; + + // 1. Seleccionar proyecto if (!projectId) { const { project } = await inquirer.prompt([ { @@ -55,20 +64,44 @@ export default class AppDeploy extends Command { type: "list", }, ]); + selectedProject = project; projectId = project.projectId; + } else { + selectedProject = projects.find(p => p.projectId === projectId); } - const projectSelected = await getProject(projectId, auth, this); + // 2. Seleccionar environment del proyecto + if (!environmentId) { + if (!selectedProject?.environments || selectedProject.environments.length === 0) { + this.error(chalk.yellow("No environments found in this project.")); + } - if (projectSelected.applications.length === 0) { - this.error(chalk.yellow("No applications found in this project.")); + const { environment } = await inquirer.prompt([ + { + choices: selectedProject.environments.map((env) => ({ + name: `${env.name} (${env.description})`, + value: env, + })), + message: "Select an environment:", + name: "environment", + type: "list", + }, + ]); + selectedEnvironment = environment; + environmentId = environment.environmentId; + } else { + selectedEnvironment = selectedProject?.environments?.find(e => e.environmentId === environmentId); } + // 3. Seleccionar application del environment if (!applicationId) { + if (!selectedEnvironment?.applications || selectedEnvironment.applications.length === 0) { + this.error(chalk.yellow("No applications found in this environment.")); + } + const appAnswers = await inquirer.prompt([ { - // @ts-ignore - choices: projectSelected.applications.map((app) => ({ + choices: selectedEnvironment.applications.map((app: Application) => ({ name: app.name, value: app.applicationId, })), diff --git a/src/commands/authenticate.ts b/src/commands/authenticate.ts index f17e0e6..c57eb49 100644 --- a/src/commands/authenticate.ts +++ b/src/commands/authenticate.ts @@ -103,7 +103,3 @@ export default class Authenticate extends Command { } } } -// curl -X 'GET' \ -// 'https://panel.jinza.app/api/project.all' \ -// -H 'accept: application/json' \ -// -H 'x-api-key: EawCkTREMhxoAqvCxJFZurgCGoDZPjYHHrLgUPghRjJTpXLaahFdhCOGfABZXTRP' \ No newline at end of file diff --git a/src/utils/shared.ts b/src/utils/shared.ts index 9d0f32b..a93d79d 100644 --- a/src/utils/shared.ts +++ b/src/utils/shared.ts @@ -5,11 +5,34 @@ import chalk from "chalk"; import type { AuthConfig } from "./utils.js"; +export type Application = { + applicationId: string; + name: string; + // Add other application properties as needed +}; + +export type Environment = { + name: string; + environmentId: string; + description: string; + createdAt: string; + env: string; + projectId: string; + applications: Application[]; + mariadb: any[]; + mongo: any[]; + mysql: any[]; + postgres: any[]; + redis: any[]; + compose: any[]; +}; + export type Project = { adminId: string; name: string; projectId?: string | undefined; description?: string | undefined; + environments?: Environment[]; }; export const getProjects = async (