@dokploy/cli 0.2.3
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/README.md +112 -0
- package/bin/dev.cmd +3 -0
- package/bin/dev.js +6 -0
- package/bin/run.cmd +3 -0
- package/bin/run.js +5 -0
- package/dist/commands/app/create.d.ts +13 -0
- package/dist/commands/app/create.js +77 -0
- package/dist/commands/app/delete.d.ts +9 -0
- package/dist/commands/app/delete.js +84 -0
- package/dist/commands/app/deploy.d.ts +6 -0
- package/dist/commands/app/deploy.js +69 -0
- package/dist/commands/app/stop.d.ts +6 -0
- package/dist/commands/app/stop.js +69 -0
- package/dist/commands/authenticate.d.ts +10 -0
- package/dist/commands/authenticate.js +79 -0
- package/dist/commands/database/mariadb/create.d.ts +9 -0
- package/dist/commands/database/mariadb/create.js +105 -0
- package/dist/commands/database/mariadb/delete.d.ts +9 -0
- package/dist/commands/database/mariadb/delete.js +95 -0
- package/dist/commands/database/mariadb/deploy.d.ts +6 -0
- package/dist/commands/database/mariadb/deploy.js +69 -0
- package/dist/commands/database/mariadb/stop.d.ts +6 -0
- package/dist/commands/database/mariadb/stop.js +69 -0
- package/dist/commands/database/mongo/create.d.ts +9 -0
- package/dist/commands/database/mongo/create.js +107 -0
- package/dist/commands/database/mongo/delete.d.ts +9 -0
- package/dist/commands/database/mongo/delete.js +95 -0
- package/dist/commands/database/mongo/deploy.d.ts +6 -0
- package/dist/commands/database/mongo/deploy.js +69 -0
- package/dist/commands/database/mongo/stop.d.ts +6 -0
- package/dist/commands/database/mongo/stop.js +69 -0
- package/dist/commands/database/mysql/create.d.ts +9 -0
- package/dist/commands/database/mysql/create.js +112 -0
- package/dist/commands/database/mysql/delete.d.ts +9 -0
- package/dist/commands/database/mysql/delete.js +97 -0
- package/dist/commands/database/mysql/deploy.d.ts +6 -0
- package/dist/commands/database/mysql/deploy.js +69 -0
- package/dist/commands/database/mysql/stop.d.ts +6 -0
- package/dist/commands/database/mysql/stop.js +69 -0
- package/dist/commands/database/postgres/create.d.ts +9 -0
- package/dist/commands/database/postgres/create.js +107 -0
- package/dist/commands/database/postgres/delete.d.ts +9 -0
- package/dist/commands/database/postgres/delete.js +94 -0
- package/dist/commands/database/postgres/deploy.d.ts +6 -0
- package/dist/commands/database/postgres/deploy.js +69 -0
- package/dist/commands/database/postgres/stop.d.ts +6 -0
- package/dist/commands/database/postgres/stop.js +69 -0
- package/dist/commands/database/redis/create.d.ts +9 -0
- package/dist/commands/database/redis/create.js +95 -0
- package/dist/commands/database/redis/delete.d.ts +9 -0
- package/dist/commands/database/redis/delete.js +96 -0
- package/dist/commands/database/redis/deploy.d.ts +6 -0
- package/dist/commands/database/redis/deploy.js +69 -0
- package/dist/commands/database/redis/stop.d.ts +6 -0
- package/dist/commands/database/redis/stop.js +69 -0
- package/dist/commands/project/create.d.ts +10 -0
- package/dist/commands/project/create.js +74 -0
- package/dist/commands/project/info.d.ts +10 -0
- package/dist/commands/project/info.js +122 -0
- package/dist/commands/project/list.d.ts +6 -0
- package/dist/commands/project/list.js +43 -0
- package/dist/commands/verify.d.ts +6 -0
- package/dist/commands/verify.js +45 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/utils/http.d.ts +4 -0
- package/dist/utils/http.js +4 -0
- package/dist/utils/shared.d.ts +10 -0
- package/dist/utils/shared.js +55 -0
- package/dist/utils/slug.d.ts +1 -0
- package/dist/utils/slug.js +12 -0
- package/dist/utils/slugify.d.ts +3 -0
- package/dist/utils/slugify.js +2 -0
- package/dist/utils/utils.d.ts +6 -0
- package/dist/utils/utils.js +19 -0
- package/oclif.manifest.json +895 -0
- package/package.json +87 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Command } from "@oclif/core";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import inquirer from "inquirer";
|
|
4
|
+
import axios from "axios";
|
|
5
|
+
import { getProject, getProjects } from "../../../utils/shared.js";
|
|
6
|
+
import { readAuthConfig } from "../../../utils/utils.js";
|
|
7
|
+
export default class DatabaseMongoStop extends Command {
|
|
8
|
+
static description = "Stop an mongo from a project.";
|
|
9
|
+
static examples = ["$ <%= config.bin %> mongo stop"];
|
|
10
|
+
async run() {
|
|
11
|
+
const auth = await readAuthConfig(this);
|
|
12
|
+
console.log(chalk.blue.bold("\n Listing all Projects \n"));
|
|
13
|
+
const projects = await getProjects(auth, this);
|
|
14
|
+
const { project } = await inquirer.prompt([
|
|
15
|
+
{
|
|
16
|
+
choices: projects.map((project) => ({
|
|
17
|
+
name: project.name,
|
|
18
|
+
value: project,
|
|
19
|
+
})),
|
|
20
|
+
message: "Select a project to stop the mongo in:",
|
|
21
|
+
name: "project",
|
|
22
|
+
type: "list",
|
|
23
|
+
},
|
|
24
|
+
]);
|
|
25
|
+
const projectId = project.projectId;
|
|
26
|
+
const projectSelected = await getProject(projectId, auth, this);
|
|
27
|
+
if (projectSelected.mongo.length === 0) {
|
|
28
|
+
this.error(chalk.yellow("No mongo found in this project."));
|
|
29
|
+
}
|
|
30
|
+
const appAnswers = await inquirer.prompt([
|
|
31
|
+
{
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
choices: projectSelected.mongo.map((app) => ({
|
|
34
|
+
name: app.name,
|
|
35
|
+
value: app.mongoId,
|
|
36
|
+
})),
|
|
37
|
+
message: "Select the mongo to stop:",
|
|
38
|
+
name: "selectedApp",
|
|
39
|
+
type: "list",
|
|
40
|
+
},
|
|
41
|
+
]);
|
|
42
|
+
const mongoId = appAnswers.selectedApp;
|
|
43
|
+
const confirmAnswers = await inquirer.prompt([
|
|
44
|
+
{
|
|
45
|
+
default: false,
|
|
46
|
+
message: "Are you sure you want to stop this mongo?",
|
|
47
|
+
name: "confirmDelete",
|
|
48
|
+
type: "confirm",
|
|
49
|
+
},
|
|
50
|
+
]);
|
|
51
|
+
if (!confirmAnswers.confirmDelete) {
|
|
52
|
+
this.error(chalk.yellow("mongo stop cancelled."));
|
|
53
|
+
}
|
|
54
|
+
const response = await axios.post(`${auth.url}/api/trpc/mongo.stop`, {
|
|
55
|
+
json: {
|
|
56
|
+
mongoId,
|
|
57
|
+
},
|
|
58
|
+
}, {
|
|
59
|
+
headers: {
|
|
60
|
+
Authorization: `Bearer ${auth.token}`,
|
|
61
|
+
"Content-Type": "application/json",
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
if (response.status !== 200) {
|
|
65
|
+
this.error(chalk.red("Error stopping mongo"));
|
|
66
|
+
}
|
|
67
|
+
this.log(chalk.green("Mongo stop successful."));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Command } from "@oclif/core";
|
|
2
|
+
export default class DatabaseMysqlCreate extends Command {
|
|
3
|
+
static description: string;
|
|
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
|
+
};
|
|
8
|
+
run(): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { Command, Flags } from "@oclif/core";
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import inquirer from "inquirer";
|
|
5
|
+
import { slugify } from "../../../utils/slug.js";
|
|
6
|
+
import { readAuthConfig } from "../../../utils/utils.js";
|
|
7
|
+
import { getProjects } from "../../../utils/shared.js";
|
|
8
|
+
export default class DatabaseMysqlCreate extends Command {
|
|
9
|
+
static description = "Create a new MySQL database within a project.";
|
|
10
|
+
static examples = ["$ <%= config.bin %> mysql create"];
|
|
11
|
+
static flags = {
|
|
12
|
+
projectId: Flags.string({
|
|
13
|
+
char: "p",
|
|
14
|
+
description: "ID of the project",
|
|
15
|
+
required: false,
|
|
16
|
+
}),
|
|
17
|
+
};
|
|
18
|
+
async run() {
|
|
19
|
+
const auth = await readAuthConfig(this);
|
|
20
|
+
const { flags } = await this.parse(DatabaseMysqlCreate);
|
|
21
|
+
let { projectId } = flags;
|
|
22
|
+
if (!projectId) {
|
|
23
|
+
console.log(chalk.blue.bold("\n Listing all Projects \n"));
|
|
24
|
+
const projects = await getProjects(auth, this);
|
|
25
|
+
const { project } = await inquirer.prompt([
|
|
26
|
+
{
|
|
27
|
+
choices: projects.map((project) => ({
|
|
28
|
+
name: project.name,
|
|
29
|
+
value: project,
|
|
30
|
+
})),
|
|
31
|
+
message: "Select a project to create the MySQL database in:",
|
|
32
|
+
name: "project",
|
|
33
|
+
type: "list",
|
|
34
|
+
},
|
|
35
|
+
]);
|
|
36
|
+
projectId = project.projectId;
|
|
37
|
+
const dbDetails = await inquirer.prompt([
|
|
38
|
+
{
|
|
39
|
+
message: "Enter the name:",
|
|
40
|
+
name: "name",
|
|
41
|
+
type: "input",
|
|
42
|
+
validate: (input) => (input ? true : "Database name is required"),
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
message: "Database name:",
|
|
46
|
+
name: "databaseName",
|
|
47
|
+
type: "input",
|
|
48
|
+
validate: (input) => (input ? true : "Database name is required"),
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
message: "Enter the database description (optional):",
|
|
52
|
+
name: "description",
|
|
53
|
+
type: "input",
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
message: "Database Root Password (optional):",
|
|
57
|
+
name: "databaseRootPassword",
|
|
58
|
+
type: "password",
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
message: "Database password (optional):",
|
|
62
|
+
name: "databasePassword",
|
|
63
|
+
type: "password",
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
default: "mysql:8",
|
|
67
|
+
message: "Docker Image (default: mysql:8):",
|
|
68
|
+
name: "dockerImage",
|
|
69
|
+
type: "input",
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
default: "mysql",
|
|
73
|
+
message: "Database User: (default: mysql):",
|
|
74
|
+
name: "databaseUser",
|
|
75
|
+
type: "input",
|
|
76
|
+
},
|
|
77
|
+
]);
|
|
78
|
+
const appName = await inquirer.prompt([
|
|
79
|
+
{
|
|
80
|
+
default: `${slugify(project.name)}-${dbDetails.name}`,
|
|
81
|
+
message: "Enter the App name:",
|
|
82
|
+
name: "appName",
|
|
83
|
+
type: "input",
|
|
84
|
+
validate: (input) => (input ? true : "App name is required"),
|
|
85
|
+
},
|
|
86
|
+
]);
|
|
87
|
+
try {
|
|
88
|
+
const response = await axios.post(`${auth.url}/api/trpc/mysql.create`, {
|
|
89
|
+
json: {
|
|
90
|
+
...dbDetails,
|
|
91
|
+
appName: appName.appName,
|
|
92
|
+
projectId: project.projectId,
|
|
93
|
+
},
|
|
94
|
+
}, {
|
|
95
|
+
headers: {
|
|
96
|
+
Authorization: `Bearer ${auth.token}`,
|
|
97
|
+
"Content-Type": "application/json",
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
if (!response.data.result.data.json) {
|
|
101
|
+
this.error(chalk.red("Error creating MySQL database"));
|
|
102
|
+
}
|
|
103
|
+
this.log(chalk.green(`MySQL database '${dbDetails.name}' created successfully.`));
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
this.error(
|
|
107
|
+
// @ts-ignore
|
|
108
|
+
chalk.red(`Failed to create MySQL database: ${error.message}`));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Command } from "@oclif/core";
|
|
2
|
+
export default class DatabaseMysqlDelete extends Command {
|
|
3
|
+
static description: string;
|
|
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
|
+
};
|
|
8
|
+
run(): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Command, Flags } from "@oclif/core";
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import inquirer from "inquirer";
|
|
5
|
+
import { readAuthConfig } from "../../../utils/utils.js";
|
|
6
|
+
import { getProject, getProjects } from "../../../utils/shared.js";
|
|
7
|
+
export default class DatabaseMysqlDelete extends Command {
|
|
8
|
+
static description = "Delete a MySQL database from a project.";
|
|
9
|
+
static examples = [
|
|
10
|
+
"$ <%= config.bin %> mysql delete",
|
|
11
|
+
"$ <%= config.bin %> mysql delete -p <projectId>",
|
|
12
|
+
];
|
|
13
|
+
static flags = {
|
|
14
|
+
projectId: Flags.string({
|
|
15
|
+
char: "p",
|
|
16
|
+
description: "ID of the project",
|
|
17
|
+
required: false,
|
|
18
|
+
}),
|
|
19
|
+
};
|
|
20
|
+
async run() {
|
|
21
|
+
const auth = await readAuthConfig(this);
|
|
22
|
+
const { flags } = await this.parse(DatabaseMysqlDelete);
|
|
23
|
+
let { projectId } = flags;
|
|
24
|
+
if (!projectId) {
|
|
25
|
+
console.log(chalk.blue.bold("\n Listing all Projects \n"));
|
|
26
|
+
const projects = await getProjects(auth, this);
|
|
27
|
+
if (projects.length === 0) {
|
|
28
|
+
this.log(chalk.yellow("No projects found."));
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const answers = await inquirer.prompt([
|
|
32
|
+
{
|
|
33
|
+
choices: projects.map((project) => ({
|
|
34
|
+
name: project.name,
|
|
35
|
+
value: project.projectId,
|
|
36
|
+
})),
|
|
37
|
+
message: "Select a project to delete the MySQL 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.mysql || project.mysql.length === 0) {
|
|
47
|
+
this.log(chalk.yellow("No MySQL databases found in this project."));
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
// Permitir al usuario seleccionar una aplicación
|
|
51
|
+
const appAnswers = await inquirer.prompt([
|
|
52
|
+
{
|
|
53
|
+
choices: project.mysql.map((app) => ({
|
|
54
|
+
name: app.name,
|
|
55
|
+
value: app.mysqlId,
|
|
56
|
+
})),
|
|
57
|
+
message: "Select the MySQL database to delete:",
|
|
58
|
+
name: "selectedApp",
|
|
59
|
+
type: "list",
|
|
60
|
+
},
|
|
61
|
+
]);
|
|
62
|
+
const mysqlId = appAnswers.selectedApp;
|
|
63
|
+
// Confirmar eliminación
|
|
64
|
+
const confirmAnswers = await inquirer.prompt([
|
|
65
|
+
{
|
|
66
|
+
default: false,
|
|
67
|
+
message: "Are you sure you want to delete this mysql database?",
|
|
68
|
+
name: "confirmDelete",
|
|
69
|
+
type: "confirm",
|
|
70
|
+
},
|
|
71
|
+
]);
|
|
72
|
+
if (!confirmAnswers.confirmDelete) {
|
|
73
|
+
this.log(chalk.yellow("Application deletion cancelled."));
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
// Eliminar la aplicación seleccionada
|
|
77
|
+
const deleteResponse = await axios.post(`${auth.url}/api/trpc/mysql.remove`, {
|
|
78
|
+
json: {
|
|
79
|
+
mysqlId,
|
|
80
|
+
},
|
|
81
|
+
}, {
|
|
82
|
+
headers: {
|
|
83
|
+
Authorization: `Bearer ${auth.token}`,
|
|
84
|
+
"Content-Type": "application/json",
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
if (!deleteResponse.data.result.data.json) {
|
|
88
|
+
this.error(chalk.red("Error deleting application"));
|
|
89
|
+
}
|
|
90
|
+
this.log(chalk.green("Application deleted successfully."));
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
// @ts-expect-error - TS2339: Property 'data' does not exist on type 'AxiosError<any>'.
|
|
94
|
+
this.error(chalk.red(`Failed to delete application: ${error.message}`));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Command } from "@oclif/core";
|
|
2
|
+
import { readAuthConfig } from "../../../utils/utils.js";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import { getProject, getProjects } from "../../../utils/shared.js";
|
|
5
|
+
import inquirer from "inquirer";
|
|
6
|
+
import axios from "axios";
|
|
7
|
+
export default class DatabaseMysqlDeploy extends Command {
|
|
8
|
+
static description = "Deploy an mysql to a project.";
|
|
9
|
+
static examples = ["$ <%= config.bin %> app deploy"];
|
|
10
|
+
async run() {
|
|
11
|
+
const auth = await readAuthConfig(this);
|
|
12
|
+
console.log(chalk.blue.bold("\n Listing all Projects \n"));
|
|
13
|
+
const projects = await getProjects(auth, this);
|
|
14
|
+
const { project } = await inquirer.prompt([
|
|
15
|
+
{
|
|
16
|
+
choices: projects.map((project) => ({
|
|
17
|
+
name: project.name,
|
|
18
|
+
value: project,
|
|
19
|
+
})),
|
|
20
|
+
message: "Select a project to deploy the mysql in:",
|
|
21
|
+
name: "project",
|
|
22
|
+
type: "list",
|
|
23
|
+
},
|
|
24
|
+
]);
|
|
25
|
+
const projectId = project.projectId;
|
|
26
|
+
const projectSelected = await getProject(projectId, auth, this);
|
|
27
|
+
if (projectSelected.mysql.length === 0) {
|
|
28
|
+
this.error(chalk.yellow("No mysql found in this project."));
|
|
29
|
+
}
|
|
30
|
+
const appAnswers = await inquirer.prompt([
|
|
31
|
+
{
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
choices: projectSelected.mysql.map((app) => ({
|
|
34
|
+
name: app.name,
|
|
35
|
+
value: app.mysqlId,
|
|
36
|
+
})),
|
|
37
|
+
message: "Select the mysql to deploy:",
|
|
38
|
+
name: "selectedApp",
|
|
39
|
+
type: "list",
|
|
40
|
+
},
|
|
41
|
+
]);
|
|
42
|
+
const mysqlId = appAnswers.selectedApp;
|
|
43
|
+
const confirmAnswers = await inquirer.prompt([
|
|
44
|
+
{
|
|
45
|
+
default: false,
|
|
46
|
+
message: "Are you sure you want to deploy this mysql?",
|
|
47
|
+
name: "confirmDelete",
|
|
48
|
+
type: "confirm",
|
|
49
|
+
},
|
|
50
|
+
]);
|
|
51
|
+
if (!confirmAnswers.confirmDelete) {
|
|
52
|
+
this.error(chalk.yellow("mysql deployment cancelled."));
|
|
53
|
+
}
|
|
54
|
+
const response = await axios.post(`${auth.url}/api/trpc/mysql.deploy`, {
|
|
55
|
+
json: {
|
|
56
|
+
mysqlId,
|
|
57
|
+
},
|
|
58
|
+
}, {
|
|
59
|
+
headers: {
|
|
60
|
+
Authorization: `Bearer ${auth.token}`,
|
|
61
|
+
"Content-Type": "application/json",
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
if (response.status !== 200) {
|
|
65
|
+
this.error(chalk.red("Error deploying mysql"));
|
|
66
|
+
}
|
|
67
|
+
this.log(chalk.green("Mysql deployed successful."));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Command } from "@oclif/core";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import inquirer from "inquirer";
|
|
4
|
+
import axios from "axios";
|
|
5
|
+
import { getProject, getProjects } from "../../../utils/shared.js";
|
|
6
|
+
import { readAuthConfig } from "../../../utils/utils.js";
|
|
7
|
+
export default class DatabaseMysqlStop extends Command {
|
|
8
|
+
static description = "Stop an mysql from a project.";
|
|
9
|
+
static examples = ["$ <%= config.bin %> mysql stop"];
|
|
10
|
+
async run() {
|
|
11
|
+
const auth = await readAuthConfig(this);
|
|
12
|
+
console.log(chalk.blue.bold("\n Listing all Projects \n"));
|
|
13
|
+
const projects = await getProjects(auth, this);
|
|
14
|
+
const { project } = await inquirer.prompt([
|
|
15
|
+
{
|
|
16
|
+
choices: projects.map((project) => ({
|
|
17
|
+
name: project.name,
|
|
18
|
+
value: project,
|
|
19
|
+
})),
|
|
20
|
+
message: "Select a project to stop the mysql in:",
|
|
21
|
+
name: "project",
|
|
22
|
+
type: "list",
|
|
23
|
+
},
|
|
24
|
+
]);
|
|
25
|
+
const projectId = project.projectId;
|
|
26
|
+
const projectSelected = await getProject(projectId, auth, this);
|
|
27
|
+
if (projectSelected.mysql.length === 0) {
|
|
28
|
+
this.error(chalk.yellow("No mysql found in this project."));
|
|
29
|
+
}
|
|
30
|
+
const appAnswers = await inquirer.prompt([
|
|
31
|
+
{
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
choices: projectSelected.mysql.map((app) => ({
|
|
34
|
+
name: app.name,
|
|
35
|
+
value: app.mysqlId,
|
|
36
|
+
})),
|
|
37
|
+
message: "Select the mysql to stop:",
|
|
38
|
+
name: "selectedApp",
|
|
39
|
+
type: "list",
|
|
40
|
+
},
|
|
41
|
+
]);
|
|
42
|
+
const mysqlId = appAnswers.selectedApp;
|
|
43
|
+
const confirmAnswers = await inquirer.prompt([
|
|
44
|
+
{
|
|
45
|
+
default: false,
|
|
46
|
+
message: "Are you sure you want to stop this mysql?",
|
|
47
|
+
name: "confirmDelete",
|
|
48
|
+
type: "confirm",
|
|
49
|
+
},
|
|
50
|
+
]);
|
|
51
|
+
if (!confirmAnswers.confirmDelete) {
|
|
52
|
+
this.error(chalk.yellow("mysql stop cancelled."));
|
|
53
|
+
}
|
|
54
|
+
const response = await axios.post(`${auth.url}/api/trpc/mysql.stop`, {
|
|
55
|
+
json: {
|
|
56
|
+
mysqlId,
|
|
57
|
+
},
|
|
58
|
+
}, {
|
|
59
|
+
headers: {
|
|
60
|
+
Authorization: `Bearer ${auth.token}`,
|
|
61
|
+
"Content-Type": "application/json",
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
if (response.status !== 200) {
|
|
65
|
+
this.error(chalk.red("Error stopping mysql"));
|
|
66
|
+
}
|
|
67
|
+
this.log(chalk.green("Mysql stop successful."));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Command } from "@oclif/core";
|
|
2
|
+
export default class DatabasePostgresCreate extends Command {
|
|
3
|
+
static description: string;
|
|
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
|
+
};
|
|
8
|
+
run(): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { Command, Flags } from "@oclif/core";
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import inquirer from "inquirer";
|
|
5
|
+
import { slugify } from "../../../utils/slug.js";
|
|
6
|
+
import { readAuthConfig } from "../../../utils/utils.js";
|
|
7
|
+
import { getProjects } from "../../../utils/shared.js";
|
|
8
|
+
export default class DatabasePostgresCreate extends Command {
|
|
9
|
+
static description = "Create a new PostgreSQL database within a project.";
|
|
10
|
+
static examples = ["$ <%= config.bin %> postgres create"];
|
|
11
|
+
static flags = {
|
|
12
|
+
projectId: Flags.string({
|
|
13
|
+
char: "p",
|
|
14
|
+
description: "ID of the project",
|
|
15
|
+
required: false,
|
|
16
|
+
}),
|
|
17
|
+
};
|
|
18
|
+
async run() {
|
|
19
|
+
const auth = await readAuthConfig(this);
|
|
20
|
+
const { flags } = await this.parse(DatabasePostgresCreate);
|
|
21
|
+
let { projectId } = flags;
|
|
22
|
+
if (!projectId) {
|
|
23
|
+
console.log(chalk.blue.bold("\n Listing all Projects \n"));
|
|
24
|
+
const projects = await getProjects(auth, this);
|
|
25
|
+
const { project } = await inquirer.prompt([
|
|
26
|
+
{
|
|
27
|
+
choices: projects.map((project) => ({
|
|
28
|
+
name: project.name,
|
|
29
|
+
value: project,
|
|
30
|
+
})),
|
|
31
|
+
message: "Select a project to create the PostgreSQL database in:",
|
|
32
|
+
name: "project",
|
|
33
|
+
type: "list",
|
|
34
|
+
},
|
|
35
|
+
]);
|
|
36
|
+
projectId = project.projectId;
|
|
37
|
+
const dbDetails = await inquirer.prompt([
|
|
38
|
+
{
|
|
39
|
+
message: "Enter the name:",
|
|
40
|
+
name: "name",
|
|
41
|
+
type: "input",
|
|
42
|
+
validate: (input) => (input ? true : "Database name is required"),
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
message: "Database name:",
|
|
46
|
+
name: "databaseName",
|
|
47
|
+
type: "input",
|
|
48
|
+
validate: (input) => (input ? true : "Database name is required"),
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
message: "Enter the database description (optional):",
|
|
52
|
+
name: "description",
|
|
53
|
+
type: "input",
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
message: "Database password (optional):",
|
|
57
|
+
name: "databasePassword",
|
|
58
|
+
type: "password",
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
default: "postgres:15",
|
|
62
|
+
message: "Docker Image (default: postgres:15):",
|
|
63
|
+
name: "dockerImage",
|
|
64
|
+
type: "input",
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
default: "postgres",
|
|
68
|
+
message: "Database User: (default: postgres):",
|
|
69
|
+
name: "databaseUser",
|
|
70
|
+
type: "input",
|
|
71
|
+
},
|
|
72
|
+
]);
|
|
73
|
+
const appName = await inquirer.prompt([
|
|
74
|
+
{
|
|
75
|
+
default: `${slugify(project.name)}-${dbDetails.name}`,
|
|
76
|
+
message: "Enter the App name:",
|
|
77
|
+
name: "appName",
|
|
78
|
+
type: "input",
|
|
79
|
+
validate: (input) => (input ? true : "App name is required"),
|
|
80
|
+
},
|
|
81
|
+
]);
|
|
82
|
+
try {
|
|
83
|
+
const response = await axios.post(`${auth.url}/api/trpc/postgres.create`, {
|
|
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 PostgreSQL database"));
|
|
97
|
+
}
|
|
98
|
+
this.log(chalk.green(`PostgreSQL database '${dbDetails.name}' created successfully.`));
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
this.error(
|
|
102
|
+
// @ts-ignore
|
|
103
|
+
chalk.red(`Failed to create PostgreSQL database: ${error.message}`));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Command } from "@oclif/core";
|
|
2
|
+
export default class DatabasePostgresDelete extends Command {
|
|
3
|
+
static description: string;
|
|
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
|
+
};
|
|
8
|
+
run(): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Command, Flags } from "@oclif/core";
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import inquirer from "inquirer";
|
|
5
|
+
import { readAuthConfig } from "../../../utils/utils.js";
|
|
6
|
+
import { getProject, getProjects } from "../../../utils/shared.js";
|
|
7
|
+
export default class DatabasePostgresDelete extends Command {
|
|
8
|
+
static description = "Delete a PostgreSQL database from a project.";
|
|
9
|
+
static examples = [
|
|
10
|
+
"$ <%= config.bin %> postgres delete",
|
|
11
|
+
"$ <%= config.bin %> postgres delete -p <projectId>",
|
|
12
|
+
];
|
|
13
|
+
static flags = {
|
|
14
|
+
projectId: Flags.string({
|
|
15
|
+
char: "p",
|
|
16
|
+
description: "ID of the project",
|
|
17
|
+
required: false,
|
|
18
|
+
}),
|
|
19
|
+
};
|
|
20
|
+
async run() {
|
|
21
|
+
const auth = await readAuthConfig(this);
|
|
22
|
+
const { flags } = await this.parse(DatabasePostgresDelete);
|
|
23
|
+
let { projectId } = flags;
|
|
24
|
+
if (!projectId) {
|
|
25
|
+
console.log(chalk.blue.bold("\n Listing all Projects \n"));
|
|
26
|
+
const projects = await getProjects(auth, this);
|
|
27
|
+
if (projects.length === 0) {
|
|
28
|
+
this.log(chalk.yellow("No projects found."));
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const answers = await inquirer.prompt([
|
|
32
|
+
{
|
|
33
|
+
choices: projects.map((project) => ({
|
|
34
|
+
name: project.name,
|
|
35
|
+
value: project.projectId,
|
|
36
|
+
})),
|
|
37
|
+
message: "Select a project to delete the PostgreSQL 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.postgres || project.postgres.length === 0) {
|
|
47
|
+
this.log(chalk.yellow("No PostgreSQL databases found in this project."));
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const appAnswers = await inquirer.prompt([
|
|
51
|
+
{
|
|
52
|
+
choices: project.postgres.map((db) => ({
|
|
53
|
+
name: db.name,
|
|
54
|
+
value: db.postgresId,
|
|
55
|
+
})),
|
|
56
|
+
message: "Select the PostgreSQL database to delete:",
|
|
57
|
+
name: "selectedApp",
|
|
58
|
+
type: "list",
|
|
59
|
+
},
|
|
60
|
+
]);
|
|
61
|
+
const postgresId = appAnswers.selectedApp;
|
|
62
|
+
const confirmAnswers = await inquirer.prompt([
|
|
63
|
+
{
|
|
64
|
+
default: false,
|
|
65
|
+
message: "Are you sure you want to delete this postgres database?",
|
|
66
|
+
name: "confirmDelete",
|
|
67
|
+
type: "confirm",
|
|
68
|
+
},
|
|
69
|
+
]);
|
|
70
|
+
if (!confirmAnswers.confirmDelete) {
|
|
71
|
+
this.log(chalk.yellow("Database deletion cancelled."));
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const deleteResponse = await axios.post(`${auth.url}/api/trpc/postgres.remove`, {
|
|
75
|
+
json: {
|
|
76
|
+
postgresId,
|
|
77
|
+
},
|
|
78
|
+
}, {
|
|
79
|
+
headers: {
|
|
80
|
+
Authorization: `Bearer ${auth.token}`,
|
|
81
|
+
"Content-Type": "application/json",
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
if (!deleteResponse.data.result.data.json) {
|
|
85
|
+
this.error(chalk.red("Error deleting PostgreSQL database"));
|
|
86
|
+
}
|
|
87
|
+
this.log(chalk.green("PostgreSQL database deleted successfully."));
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
// @ts-expect-error - TS2339: Property 'data' does not exist on type 'AxiosError<any>'.
|
|
91
|
+
this.error(chalk.red(`Failed to delete application: ${error.message}`));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|