Skip to content

Commit d32c3b2

Browse files
committed
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.
1 parent 82aed68 commit d32c3b2

File tree

3 files changed

+64
-12
lines changed

3 files changed

+64
-12
lines changed

src/commands/app/deploy.ts

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Command, Flags } from "@oclif/core";
22
import { readAuthConfig } from "../../utils/utils.js";
33
import chalk from "chalk";
4-
import { getProject, getProjects } from "../../utils/shared.js";
4+
import { getProject, getProjects, type Application } from "../../utils/shared.js";
55
import inquirer from "inquirer";
66
import type { Answers } from "./create.js";
77
import axios from "axios";
@@ -26,6 +26,11 @@ export default class AppDeploy extends Command {
2626
description: 'ID of the project',
2727
required: false,
2828
}),
29+
environmentId: Flags.string({
30+
char: 'e',
31+
description: 'ID of the environment',
32+
required: false,
33+
}),
2934
skipConfirm: Flags.boolean({
3035
char: 'y',
3136
description: 'Skip confirmation prompt',
@@ -36,13 +41,17 @@ export default class AppDeploy extends Command {
3641
public async run(): Promise<void> {
3742
const auth = await readAuthConfig(this);
3843
const { flags } = await this.parse(AppDeploy);
39-
let { projectId, applicationId } = flags;
44+
let { projectId, applicationId, environmentId } = flags;
4045

4146
// Modo interactivo si no se proporcionan los flags necesarios
42-
if (!projectId || !applicationId) {
47+
if (!projectId || !applicationId || !environmentId) {
4348
console.log(chalk.blue.bold("\n Listing all Projects \n"));
4449
const projects = await getProjects(auth, this);
4550

51+
let selectedProject;
52+
let selectedEnvironment;
53+
54+
// 1. Seleccionar proyecto
4655
if (!projectId) {
4756
const { project } = await inquirer.prompt<Answers>([
4857
{
@@ -55,20 +64,44 @@ export default class AppDeploy extends Command {
5564
type: "list",
5665
},
5766
]);
67+
selectedProject = project;
5868
projectId = project.projectId;
69+
} else {
70+
selectedProject = projects.find(p => p.projectId === projectId);
5971
}
6072

61-
const projectSelected = await getProject(projectId, auth, this);
73+
// 2. Seleccionar environment del proyecto
74+
if (!environmentId) {
75+
if (!selectedProject?.environments || selectedProject.environments.length === 0) {
76+
this.error(chalk.yellow("No environments found in this project."));
77+
}
6278

63-
if (projectSelected.applications.length === 0) {
64-
this.error(chalk.yellow("No applications found in this project."));
79+
const { environment } = await inquirer.prompt([
80+
{
81+
choices: selectedProject.environments.map((env) => ({
82+
name: `${env.name} (${env.description})`,
83+
value: env,
84+
})),
85+
message: "Select an environment:",
86+
name: "environment",
87+
type: "list",
88+
},
89+
]);
90+
selectedEnvironment = environment;
91+
environmentId = environment.environmentId;
92+
} else {
93+
selectedEnvironment = selectedProject?.environments?.find(e => e.environmentId === environmentId);
6594
}
6695

96+
// 3. Seleccionar application del environment
6797
if (!applicationId) {
98+
if (!selectedEnvironment?.applications || selectedEnvironment.applications.length === 0) {
99+
this.error(chalk.yellow("No applications found in this environment."));
100+
}
101+
68102
const appAnswers = await inquirer.prompt([
69103
{
70-
// @ts-ignore
71-
choices: projectSelected.applications.map((app) => ({
104+
choices: selectedEnvironment.applications.map((app: Application) => ({
72105
name: app.name,
73106
value: app.applicationId,
74107
})),

src/commands/authenticate.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,3 @@ export default class Authenticate extends Command {
103103
}
104104
}
105105
}
106-
// curl -X 'GET' \
107-
// 'https://panel.jinza.app/api/project.all' \
108-
// -H 'accept: application/json' \
109-
// -H 'x-api-key: EawCkTREMhxoAqvCxJFZurgCGoDZPjYHHrLgUPghRjJTpXLaahFdhCOGfABZXTRP'

src/utils/shared.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,34 @@ import chalk from "chalk";
55

66
import type { AuthConfig } from "./utils.js";
77

8+
export type Application = {
9+
applicationId: string;
10+
name: string;
11+
// Add other application properties as needed
12+
};
13+
14+
export type Environment = {
15+
name: string;
16+
environmentId: string;
17+
description: string;
18+
createdAt: string;
19+
env: string;
20+
projectId: string;
21+
applications: Application[];
22+
mariadb: any[];
23+
mongo: any[];
24+
mysql: any[];
25+
postgres: any[];
26+
redis: any[];
27+
compose: any[];
28+
};
29+
830
export type Project = {
931
adminId: string;
1032
name: string;
1133
projectId?: string | undefined;
1234
description?: string | undefined;
35+
environments?: Environment[];
1336
};
1437

1538
export const getProjects = async (

0 commit comments

Comments
 (0)