@dokploy/cli 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/app/create.d.ts +4 -0
- package/dist/commands/app/create.js +87 -37
- package/dist/commands/app/delete.d.ts +2 -0
- package/dist/commands/app/delete.js +50 -28
- package/dist/commands/app/deploy.d.ts +5 -0
- package/dist/commands/app/deploy.js +93 -55
- package/dist/commands/app/stop.d.ts +5 -0
- package/dist/commands/app/stop.js +87 -54
- package/dist/commands/database/mariadb/create.d.ts +9 -0
- package/dist/commands/database/mariadb/create.js +160 -66
- package/dist/commands/database/mariadb/delete.d.ts +2 -0
- package/dist/commands/database/mariadb/delete.js +56 -47
- package/dist/commands/database/mariadb/deploy.d.ts +5 -0
- package/dist/commands/database/mariadb/deploy.js +88 -54
- package/dist/commands/database/mariadb/stop.d.ts +5 -0
- package/dist/commands/database/mariadb/stop.js +88 -54
- package/dist/commands/database/mongo/create.d.ts +8 -0
- package/dist/commands/database/mongo/create.js +145 -76
- package/dist/commands/database/mongo/delete.d.ts +2 -0
- package/dist/commands/database/mongo/delete.js +56 -45
- package/dist/commands/database/mongo/deploy.d.ts +5 -0
- package/dist/commands/database/mongo/deploy.js +88 -54
- package/dist/commands/database/mongo/stop.d.ts +5 -0
- package/dist/commands/database/mongo/stop.js +88 -54
- package/dist/commands/database/mysql/create.d.ts +9 -0
- package/dist/commands/database/mysql/create.js +168 -81
- package/dist/commands/database/mysql/delete.d.ts +2 -0
- package/dist/commands/database/mysql/delete.js +56 -47
- package/dist/commands/database/mysql/deploy.js +70 -53
- package/dist/commands/database/mysql/stop.js +70 -53
- package/dist/commands/database/postgres/create.d.ts +8 -0
- package/dist/commands/database/postgres/create.js +155 -76
- package/dist/commands/database/postgres/delete.d.ts +2 -0
- package/dist/commands/database/postgres/delete.js +56 -44
- package/dist/commands/database/postgres/deploy.d.ts +5 -0
- package/dist/commands/database/postgres/deploy.js +90 -56
- package/dist/commands/database/postgres/stop.d.ts +5 -0
- package/dist/commands/database/postgres/stop.js +91 -57
- package/dist/commands/database/redis/create.d.ts +6 -0
- package/dist/commands/database/redis/create.js +129 -65
- package/dist/commands/database/redis/delete.d.ts +2 -0
- package/dist/commands/database/redis/delete.js +60 -50
- package/dist/commands/database/redis/deploy.d.ts +5 -0
- package/dist/commands/database/redis/deploy.js +90 -56
- package/dist/commands/database/redis/stop.d.ts +5 -0
- package/dist/commands/database/redis/stop.js +91 -57
- package/dist/commands/project/create.d.ts +2 -1
- package/dist/commands/project/create.js +53 -34
- package/dist/utils/utils.js +9 -2
- package/oclif.manifest.json +876 -151
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Command } from "@oclif/core";
|
|
1
|
+
import { Command, Flags } from "@oclif/core";
|
|
2
2
|
import chalk from "chalk";
|
|
3
3
|
import inquirer from "inquirer";
|
|
4
4
|
import axios from "axios";
|
|
@@ -7,63 +7,97 @@ import { readAuthConfig } from "../../../utils/utils.js";
|
|
|
7
7
|
export default class DatabaseMariadbStop extends Command {
|
|
8
8
|
static description = "Stop an mariadb from a project.";
|
|
9
9
|
static examples = ["$ <%= config.bin %> mariadb stop"];
|
|
10
|
+
static flags = {
|
|
11
|
+
projectId: Flags.string({
|
|
12
|
+
char: "p",
|
|
13
|
+
description: "ID of the project",
|
|
14
|
+
required: false,
|
|
15
|
+
}),
|
|
16
|
+
mariadbId: Flags.string({
|
|
17
|
+
char: "m",
|
|
18
|
+
description: "ID of the MariaDB instance to stop",
|
|
19
|
+
required: false,
|
|
20
|
+
}),
|
|
21
|
+
skipConfirm: Flags.boolean({
|
|
22
|
+
char: "y",
|
|
23
|
+
description: "Skip confirmation prompt",
|
|
24
|
+
default: false,
|
|
25
|
+
}),
|
|
26
|
+
};
|
|
10
27
|
async run() {
|
|
11
28
|
const auth = await readAuthConfig(this);
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
const { flags } = await this.parse(DatabaseMariadbStop);
|
|
30
|
+
let { projectId, mariadbId } = flags;
|
|
31
|
+
// Modo interactivo si no se proporcionan los flags necesarios
|
|
32
|
+
if (!projectId || !mariadbId) {
|
|
33
|
+
console.log(chalk.blue.bold("\n Listing all Projects \n"));
|
|
34
|
+
const projects = await getProjects(auth, this);
|
|
35
|
+
if (!projectId) {
|
|
36
|
+
const { project } = await inquirer.prompt([
|
|
37
|
+
{
|
|
38
|
+
choices: projects.map((project) => ({
|
|
39
|
+
name: project.name,
|
|
40
|
+
value: project,
|
|
41
|
+
})),
|
|
42
|
+
message: "Select a project to stop the MariaDB instance from:",
|
|
43
|
+
name: "project",
|
|
44
|
+
type: "list",
|
|
45
|
+
},
|
|
46
|
+
]);
|
|
47
|
+
projectId = project.projectId;
|
|
48
|
+
}
|
|
49
|
+
const projectSelected = await getProject(projectId, auth, this);
|
|
50
|
+
if (projectSelected.mariadb.length === 0) {
|
|
51
|
+
this.error(chalk.yellow("No MariaDB instances found in this project."));
|
|
52
|
+
}
|
|
53
|
+
if (!mariadbId) {
|
|
54
|
+
const dbAnswers = await inquirer.prompt([
|
|
55
|
+
{
|
|
56
|
+
// @ts-ignore
|
|
57
|
+
choices: projectSelected.mariadb.map((db) => ({
|
|
58
|
+
name: db.name,
|
|
59
|
+
value: db.mariadbId,
|
|
60
|
+
})),
|
|
61
|
+
message: "Select the MariaDB instance to stop:",
|
|
62
|
+
name: "selectedDb",
|
|
63
|
+
type: "list",
|
|
64
|
+
},
|
|
65
|
+
]);
|
|
66
|
+
mariadbId = dbAnswers.selectedDb;
|
|
67
|
+
}
|
|
29
68
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const confirmAnswers = await inquirer.prompt([
|
|
44
|
-
{
|
|
45
|
-
default: false,
|
|
46
|
-
message: "Are you sure you want to stop this mariadb?",
|
|
47
|
-
name: "confirmDelete",
|
|
48
|
-
type: "confirm",
|
|
49
|
-
},
|
|
50
|
-
]);
|
|
51
|
-
if (!confirmAnswers.confirmDelete) {
|
|
52
|
-
this.error(chalk.yellow("Mariadb stop cancelled."));
|
|
69
|
+
// Confirmar si no se especifica --skipConfirm
|
|
70
|
+
if (!flags.skipConfirm) {
|
|
71
|
+
const confirmAnswers = await inquirer.prompt([
|
|
72
|
+
{
|
|
73
|
+
default: false,
|
|
74
|
+
message: "Are you sure you want to stop this MariaDB instance?",
|
|
75
|
+
name: "confirmStop",
|
|
76
|
+
type: "confirm",
|
|
77
|
+
},
|
|
78
|
+
]);
|
|
79
|
+
if (!confirmAnswers.confirmStop) {
|
|
80
|
+
this.error(chalk.yellow("MariaDB stop cancelled."));
|
|
81
|
+
}
|
|
53
82
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
83
|
+
try {
|
|
84
|
+
const response = await axios.post(`${auth.url}/api/trpc/mariadb.stop`, {
|
|
85
|
+
json: {
|
|
86
|
+
mariadbId,
|
|
87
|
+
},
|
|
88
|
+
}, {
|
|
89
|
+
headers: {
|
|
90
|
+
Authorization: `Bearer ${auth.token}`,
|
|
91
|
+
"Content-Type": "application/json",
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
if (response.status !== 200) {
|
|
95
|
+
this.error(chalk.red("Error stopping MariaDB instance"));
|
|
96
|
+
}
|
|
97
|
+
this.log(chalk.green("MariaDB instance stopped successfully."));
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
this.error(chalk.red(`Error stopping MariaDB instance: ${error.message}`));
|
|
66
101
|
}
|
|
67
|
-
this.log(chalk.green("Mariadb stop successful."));
|
|
68
102
|
}
|
|
69
103
|
}
|
|
@@ -4,6 +4,14 @@ export default class DatabaseMongoCreate extends Command {
|
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static flags: {
|
|
6
6
|
projectId: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
7
|
+
name: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
8
|
+
databaseName: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
9
|
+
description: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
10
|
+
databasePassword: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
11
|
+
databaseUser: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
12
|
+
dockerImage: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
13
|
+
skipConfirm: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
|
|
14
|
+
appName: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
7
15
|
};
|
|
8
16
|
run(): Promise<void>;
|
|
9
17
|
}
|
|
@@ -14,94 +14,163 @@ export default class DatabaseMongoCreate extends Command {
|
|
|
14
14
|
description: "ID of the project",
|
|
15
15
|
required: false,
|
|
16
16
|
}),
|
|
17
|
+
name: Flags.string({
|
|
18
|
+
char: "n",
|
|
19
|
+
description: "Database name",
|
|
20
|
+
required: false,
|
|
21
|
+
}),
|
|
22
|
+
databaseName: Flags.string({
|
|
23
|
+
description: "MongoDB database name",
|
|
24
|
+
required: false,
|
|
25
|
+
}),
|
|
26
|
+
description: Flags.string({
|
|
27
|
+
char: "d",
|
|
28
|
+
description: "Database description",
|
|
29
|
+
required: false,
|
|
30
|
+
}),
|
|
31
|
+
databasePassword: Flags.string({
|
|
32
|
+
description: "Database password",
|
|
33
|
+
required: false,
|
|
34
|
+
}),
|
|
35
|
+
databaseUser: Flags.string({
|
|
36
|
+
description: "Database user",
|
|
37
|
+
default: "mongo",
|
|
38
|
+
}),
|
|
39
|
+
dockerImage: Flags.string({
|
|
40
|
+
description: "Docker image",
|
|
41
|
+
default: "mongo:6",
|
|
42
|
+
}),
|
|
43
|
+
skipConfirm: Flags.boolean({
|
|
44
|
+
char: "y",
|
|
45
|
+
description: "Skip confirmation prompt",
|
|
46
|
+
default: false,
|
|
47
|
+
}),
|
|
48
|
+
appName: Flags.string({
|
|
49
|
+
description: "App name",
|
|
50
|
+
required: false,
|
|
51
|
+
}),
|
|
17
52
|
};
|
|
18
53
|
async run() {
|
|
19
54
|
const auth = await readAuthConfig(this);
|
|
20
55
|
const { flags } = await this.parse(DatabaseMongoCreate);
|
|
21
|
-
let { projectId } = flags;
|
|
22
|
-
|
|
56
|
+
let { projectId, name, databaseName, description, databasePassword, databaseUser, dockerImage, appName } = flags;
|
|
57
|
+
// Modo interactivo si no se proporcionan los flags necesarios
|
|
58
|
+
if (!projectId || !name || !databaseName || !appName || !databasePassword) {
|
|
23
59
|
console.log(chalk.blue.bold("\n Listing all Projects \n"));
|
|
24
60
|
const projects = await getProjects(auth, this);
|
|
25
|
-
|
|
61
|
+
if (!projectId) {
|
|
62
|
+
const { project } = await inquirer.prompt([
|
|
63
|
+
{
|
|
64
|
+
choices: projects.map((project) => ({
|
|
65
|
+
name: project.name,
|
|
66
|
+
value: project,
|
|
67
|
+
})),
|
|
68
|
+
message: "Select a project to create the MongoDB instance in:",
|
|
69
|
+
name: "project",
|
|
70
|
+
type: "list",
|
|
71
|
+
},
|
|
72
|
+
]);
|
|
73
|
+
projectId = project.projectId;
|
|
74
|
+
}
|
|
75
|
+
if (!name || !databaseName || !appName || !databasePassword) {
|
|
76
|
+
const dbDetails = await inquirer.prompt([
|
|
77
|
+
{
|
|
78
|
+
message: "Enter the name:",
|
|
79
|
+
name: "name",
|
|
80
|
+
type: "input",
|
|
81
|
+
validate: (input) => (input ? true : "Database name is required"),
|
|
82
|
+
default: name,
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
message: "Database name:",
|
|
86
|
+
name: "databaseName",
|
|
87
|
+
type: "input",
|
|
88
|
+
validate: (input) => (input ? true : "Database name is required"),
|
|
89
|
+
default: databaseName,
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
message: "Enter the database description (optional):",
|
|
93
|
+
name: "description",
|
|
94
|
+
type: "input",
|
|
95
|
+
default: description,
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
message: "Database password (optional):",
|
|
99
|
+
name: "databasePassword",
|
|
100
|
+
type: "password",
|
|
101
|
+
default: databasePassword,
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
default: dockerImage || "mongo:6",
|
|
105
|
+
message: "Docker Image (default: mongo:6):",
|
|
106
|
+
name: "dockerImage",
|
|
107
|
+
type: "input",
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
default: databaseUser || "mongo",
|
|
111
|
+
message: "Database User: (default: mongo):",
|
|
112
|
+
name: "databaseUser",
|
|
113
|
+
type: "input",
|
|
114
|
+
},
|
|
115
|
+
]);
|
|
116
|
+
name = dbDetails.name;
|
|
117
|
+
databaseName = dbDetails.databaseName;
|
|
118
|
+
description = dbDetails.description;
|
|
119
|
+
databasePassword = dbDetails.databasePassword;
|
|
120
|
+
dockerImage = dbDetails.dockerImage;
|
|
121
|
+
databaseUser = dbDetails.databaseUser;
|
|
122
|
+
const appNamePrompt = await inquirer.prompt([
|
|
123
|
+
{
|
|
124
|
+
default: appName || `${slugify(name)}`,
|
|
125
|
+
message: "Enter the App name:",
|
|
126
|
+
name: "appName",
|
|
127
|
+
type: "input",
|
|
128
|
+
validate: (input) => (input ? true : "App name is required"),
|
|
129
|
+
},
|
|
130
|
+
]);
|
|
131
|
+
appName = appNamePrompt.appName;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// Confirmar si no se especifica --skipConfirm
|
|
135
|
+
if (!flags.skipConfirm) {
|
|
136
|
+
const confirm = await inquirer.prompt([
|
|
26
137
|
{
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
message: "Select a project to create the MongoDB database in:",
|
|
32
|
-
name: "project",
|
|
33
|
-
type: "list",
|
|
138
|
+
type: 'confirm',
|
|
139
|
+
name: 'proceed',
|
|
140
|
+
message: 'Do you want to create this MongoDB instance?',
|
|
141
|
+
default: false,
|
|
34
142
|
},
|
|
35
143
|
]);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
name: "description",
|
|
53
|
-
type: "input",
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
message: "Database password (optional):",
|
|
57
|
-
name: "databasePassword",
|
|
58
|
-
type: "password",
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
default: "mongo:6",
|
|
62
|
-
message: "Docker Image (default: mongo:6):",
|
|
63
|
-
name: "dockerImage",
|
|
64
|
-
type: "input",
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
default: "mongo",
|
|
68
|
-
message: "Database User: (default: mongo):",
|
|
69
|
-
name: "databaseUser",
|
|
70
|
-
type: "input",
|
|
144
|
+
if (!confirm.proceed) {
|
|
145
|
+
this.error(chalk.yellow("MongoDB creation cancelled."));
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
try {
|
|
150
|
+
const response = await axios.post(`${auth.url}/api/trpc/mongo.create`, {
|
|
151
|
+
json: {
|
|
152
|
+
name,
|
|
153
|
+
databaseName,
|
|
154
|
+
description,
|
|
155
|
+
databasePassword,
|
|
156
|
+
databaseUser,
|
|
157
|
+
dockerImage,
|
|
158
|
+
appName,
|
|
159
|
+
projectId,
|
|
71
160
|
},
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
message: "Enter the App name:",
|
|
77
|
-
name: "appName",
|
|
78
|
-
type: "input",
|
|
79
|
-
validate: (input) => (input ? true : "App name is required"),
|
|
161
|
+
}, {
|
|
162
|
+
headers: {
|
|
163
|
+
Authorization: `Bearer ${auth.token}`,
|
|
164
|
+
"Content-Type": "application/json",
|
|
80
165
|
},
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
json: {
|
|
85
|
-
...dbDetails,
|
|
86
|
-
appName: appName.appName,
|
|
87
|
-
projectId: project.projectId,
|
|
88
|
-
},
|
|
89
|
-
}, {
|
|
90
|
-
headers: {
|
|
91
|
-
Authorization: `Bearer ${auth.token}`,
|
|
92
|
-
"Content-Type": "application/json",
|
|
93
|
-
},
|
|
94
|
-
});
|
|
95
|
-
if (!response.data.result.data.json) {
|
|
96
|
-
this.error(chalk.red("Error creating MongoDB database"));
|
|
97
|
-
}
|
|
98
|
-
this.log(chalk.green(`MongoDB database '${dbDetails.name}' created successfully.`));
|
|
99
|
-
}
|
|
100
|
-
catch (error) {
|
|
101
|
-
this.error(
|
|
102
|
-
// @ts-ignore
|
|
103
|
-
chalk.red(`Failed to create MongoDB database: ${error.message}`));
|
|
166
|
+
});
|
|
167
|
+
if (!response.data.result.data.json) {
|
|
168
|
+
this.error(chalk.red("Error creating MongoDB instance"));
|
|
104
169
|
}
|
|
170
|
+
this.log(chalk.green(`MongoDB instance '${name}' created successfully.`));
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
this.error(chalk.red(`Error creating MongoDB instance: ${error.message}`));
|
|
105
174
|
}
|
|
106
175
|
}
|
|
107
176
|
}
|
|
@@ -4,6 +4,8 @@ export default class DatabaseMongoDelete extends Command {
|
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static flags: {
|
|
6
6
|
projectId: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
7
|
+
mongoId: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
8
|
+
skipConfirm: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
|
|
7
9
|
};
|
|
8
10
|
run(): Promise<void>;
|
|
9
11
|
}
|
|
@@ -16,62 +16,75 @@ export default class DatabaseMongoDelete extends Command {
|
|
|
16
16
|
description: "ID of the project",
|
|
17
17
|
required: false,
|
|
18
18
|
}),
|
|
19
|
+
mongoId: Flags.string({
|
|
20
|
+
char: "m",
|
|
21
|
+
description: "ID of the MongoDB instance to delete",
|
|
22
|
+
required: false,
|
|
23
|
+
}),
|
|
24
|
+
skipConfirm: Flags.boolean({
|
|
25
|
+
char: "y",
|
|
26
|
+
description: "Skip confirmation prompt",
|
|
27
|
+
default: false,
|
|
28
|
+
}),
|
|
19
29
|
};
|
|
20
30
|
async run() {
|
|
21
31
|
const auth = await readAuthConfig(this);
|
|
22
32
|
const { flags } = await this.parse(DatabaseMongoDelete);
|
|
23
|
-
let { projectId } = flags;
|
|
24
|
-
|
|
33
|
+
let { projectId, mongoId } = flags;
|
|
34
|
+
// Modo interactivo si no se proporcionan los flags necesarios
|
|
35
|
+
if (!projectId || !mongoId) {
|
|
25
36
|
console.log(chalk.blue.bold("\n Listing all Projects \n"));
|
|
26
37
|
const projects = await getProjects(auth, this);
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
|
|
38
|
+
if (!projectId) {
|
|
39
|
+
const answers = await inquirer.prompt([
|
|
40
|
+
{
|
|
41
|
+
choices: projects.map((project) => ({
|
|
42
|
+
name: project.name,
|
|
43
|
+
value: project.projectId,
|
|
44
|
+
})),
|
|
45
|
+
message: "Select a project to delete the MongoDB instance from:",
|
|
46
|
+
name: "selectedProject",
|
|
47
|
+
type: "list",
|
|
48
|
+
},
|
|
49
|
+
]);
|
|
50
|
+
projectId = answers.selectedProject;
|
|
30
51
|
}
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
name: project.name,
|
|
35
|
-
value: project.projectId,
|
|
36
|
-
})),
|
|
37
|
-
message: "Select a project to delete the MongoDB database from:",
|
|
38
|
-
name: "selectedProject",
|
|
39
|
-
type: "list",
|
|
40
|
-
},
|
|
41
|
-
]);
|
|
42
|
-
projectId = answers.selectedProject;
|
|
43
|
-
}
|
|
44
|
-
try {
|
|
45
|
-
const project = await getProject(projectId, auth, this);
|
|
46
|
-
if (!project.mongo || project.mongo.length === 0) {
|
|
47
|
-
this.log(chalk.yellow("No MongoDB databases found in this project."));
|
|
48
|
-
return;
|
|
52
|
+
const projectSelected = await getProject(projectId, auth, this);
|
|
53
|
+
if (!projectSelected.mongo || projectSelected.mongo.length === 0) {
|
|
54
|
+
this.error(chalk.yellow("No MongoDB instances found in this project."));
|
|
49
55
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
if (!mongoId) {
|
|
57
|
+
const dbAnswers = await inquirer.prompt([
|
|
58
|
+
{
|
|
59
|
+
// @ts-ignore
|
|
60
|
+
choices: projectSelected.mongo.map((db) => ({
|
|
61
|
+
name: db.name,
|
|
62
|
+
value: db.mongoId,
|
|
63
|
+
})),
|
|
64
|
+
message: "Select the MongoDB instance to delete:",
|
|
65
|
+
name: "selectedDb",
|
|
66
|
+
type: "list",
|
|
67
|
+
},
|
|
68
|
+
]);
|
|
69
|
+
mongoId = dbAnswers.selectedDb;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// Confirmar si no se especifica --skipConfirm
|
|
73
|
+
if (!flags.skipConfirm) {
|
|
62
74
|
const confirmAnswers = await inquirer.prompt([
|
|
63
75
|
{
|
|
64
76
|
default: false,
|
|
65
|
-
message: "Are you sure you want to delete this MongoDB
|
|
77
|
+
message: "Are you sure you want to delete this MongoDB instance?",
|
|
66
78
|
name: "confirmDelete",
|
|
67
79
|
type: "confirm",
|
|
68
80
|
},
|
|
69
81
|
]);
|
|
70
82
|
if (!confirmAnswers.confirmDelete) {
|
|
71
|
-
this.
|
|
72
|
-
return;
|
|
83
|
+
this.error(chalk.yellow("MongoDB deletion cancelled."));
|
|
73
84
|
}
|
|
74
|
-
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
const response = await axios.post(`${auth.url}/api/trpc/mongo.remove`, {
|
|
75
88
|
json: {
|
|
76
89
|
mongoId,
|
|
77
90
|
},
|
|
@@ -81,15 +94,13 @@ export default class DatabaseMongoDelete extends Command {
|
|
|
81
94
|
"Content-Type": "application/json",
|
|
82
95
|
},
|
|
83
96
|
});
|
|
84
|
-
if (!
|
|
85
|
-
this.error(chalk.red("Error deleting MongoDB
|
|
97
|
+
if (!response.data.result.data.json) {
|
|
98
|
+
this.error(chalk.red("Error deleting MongoDB instance"));
|
|
86
99
|
}
|
|
87
|
-
this.log(chalk.green("MongoDB
|
|
100
|
+
this.log(chalk.green("MongoDB instance deleted successfully."));
|
|
88
101
|
}
|
|
89
102
|
catch (error) {
|
|
90
|
-
this.error(
|
|
91
|
-
// @ts-ignore
|
|
92
|
-
chalk.red(`Failed to delete MongoDB database: ${error.message}`));
|
|
103
|
+
this.error(chalk.red(`Error deleting MongoDB instance: ${error.message}`));
|
|
93
104
|
}
|
|
94
105
|
}
|
|
95
106
|
}
|
|
@@ -2,5 +2,10 @@ import { Command } from "@oclif/core";
|
|
|
2
2
|
export default class DatabaseMongoDeploy extends Command {
|
|
3
3
|
static description: string;
|
|
4
4
|
static examples: string[];
|
|
5
|
+
static flags: {
|
|
6
|
+
projectId: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
7
|
+
mongoId: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
8
|
+
skipConfirm: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
|
|
9
|
+
};
|
|
5
10
|
run(): Promise<void>;
|
|
6
11
|
}
|