@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,105 @@
|
|
|
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 { getProjects } from "../../../utils/shared.js";
|
|
7
|
+
import { slugify } from "../../../utils/slug.js";
|
|
8
|
+
export default class DatabaseMariadbCreate extends Command {
|
|
9
|
+
static description = "Create a new MariaDB database within a project.";
|
|
10
|
+
static examples = ["$ <%= config.bin %> mariadb 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(DatabaseMariadbCreate);
|
|
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 MariaDB 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: "mariadb:11",
|
|
67
|
+
message: "Docker Image (default: mariadb:11):",
|
|
68
|
+
name: "dockerImage",
|
|
69
|
+
type: "input",
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
default: "mariadb",
|
|
73
|
+
message: "Database User: (default: mariadb):",
|
|
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
|
+
const response = await axios.post(`${auth.url}/api/trpc/mariadb.create`, {
|
|
88
|
+
json: {
|
|
89
|
+
...dbDetails,
|
|
90
|
+
appName: appName.appName,
|
|
91
|
+
projectId: project.projectId,
|
|
92
|
+
},
|
|
93
|
+
}, {
|
|
94
|
+
headers: {
|
|
95
|
+
Authorization: `Bearer ${auth.token}`,
|
|
96
|
+
"Content-Type": "application/json",
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
if (!response.data.result.data.json) {
|
|
100
|
+
this.error(chalk.red("Error creating MariaDB database"));
|
|
101
|
+
}
|
|
102
|
+
this.log(chalk.green(`MariaDB database '${dbDetails.name}' created successfully.`));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Command } from "@oclif/core";
|
|
2
|
+
export default class DatabaseMariadbDelete 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,95 @@
|
|
|
1
|
+
import { Command, Flags } from "@oclif/core";
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import inquirer from "inquirer";
|
|
5
|
+
import { getProject, getProjects } from "../../../utils/shared.js";
|
|
6
|
+
import { readAuthConfig } from "../../../utils/utils.js";
|
|
7
|
+
export default class DatabaseMariadbDelete extends Command {
|
|
8
|
+
static description = "Delete a MariaDB database from a project.";
|
|
9
|
+
static examples = [
|
|
10
|
+
"$ <%= config.bin %> mariadb delete",
|
|
11
|
+
"$ <%= config.bin %> mariadb 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(DatabaseMariadbDelete);
|
|
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
|
+
type: "list",
|
|
34
|
+
name: "selectedProject",
|
|
35
|
+
message: "Select a project to delete the MariaDB database from:",
|
|
36
|
+
choices: projects.map((project) => ({
|
|
37
|
+
name: project.name,
|
|
38
|
+
value: project.projectId,
|
|
39
|
+
})),
|
|
40
|
+
},
|
|
41
|
+
]);
|
|
42
|
+
projectId = answers.selectedProject;
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
const project = await getProject(projectId, auth, this);
|
|
46
|
+
if (!project.mariadb || project.mariadb.length === 0) {
|
|
47
|
+
this.log(chalk.yellow("No MariaDB databases found in this project."));
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const appAnswers = await inquirer.prompt([
|
|
51
|
+
{
|
|
52
|
+
type: "list",
|
|
53
|
+
name: "selectedDb",
|
|
54
|
+
message: "Select the MariaDB database to delete:",
|
|
55
|
+
choices: project.mariadb.map((db) => ({
|
|
56
|
+
name: db.name,
|
|
57
|
+
value: db.mariadbId,
|
|
58
|
+
})),
|
|
59
|
+
},
|
|
60
|
+
]);
|
|
61
|
+
const mariadbId = appAnswers.selectedDb;
|
|
62
|
+
const confirmAnswers = await inquirer.prompt([
|
|
63
|
+
{
|
|
64
|
+
type: "confirm",
|
|
65
|
+
name: "confirmDelete",
|
|
66
|
+
message: "Are you sure you want to delete this MariaDB database?",
|
|
67
|
+
default: false,
|
|
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/mariadb.remove`, {
|
|
75
|
+
json: {
|
|
76
|
+
mariadbId,
|
|
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 mariadb database"));
|
|
86
|
+
}
|
|
87
|
+
this.log(chalk.green("MariaDB database deleted successfully."));
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
this.error(
|
|
91
|
+
// @ts-ignore
|
|
92
|
+
chalk.red(`Failed to delete MariaDB database: ${error.message}`));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -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 DatabaseMariadbDeploy extends Command {
|
|
8
|
+
static description = "Deploy an mariadb 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 mariadb 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.mariadb.length === 0) {
|
|
28
|
+
this.error(chalk.yellow("No mariadb found in this project."));
|
|
29
|
+
}
|
|
30
|
+
const appAnswers = await inquirer.prompt([
|
|
31
|
+
{
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
choices: projectSelected.mariadb.map((app) => ({
|
|
34
|
+
name: app.name,
|
|
35
|
+
value: app.mariadbId,
|
|
36
|
+
})),
|
|
37
|
+
message: "Select the mariadb to deploy:",
|
|
38
|
+
name: "selectedApp",
|
|
39
|
+
type: "list",
|
|
40
|
+
},
|
|
41
|
+
]);
|
|
42
|
+
const mariadbId = appAnswers.selectedApp;
|
|
43
|
+
const confirmAnswers = await inquirer.prompt([
|
|
44
|
+
{
|
|
45
|
+
default: false,
|
|
46
|
+
message: "Are you sure you want to deploy this mariadb?",
|
|
47
|
+
name: "confirmDelete",
|
|
48
|
+
type: "confirm",
|
|
49
|
+
},
|
|
50
|
+
]);
|
|
51
|
+
if (!confirmAnswers.confirmDelete) {
|
|
52
|
+
this.error(chalk.yellow("mariadb deployment cancelled."));
|
|
53
|
+
}
|
|
54
|
+
const response = await axios.post(`${auth.url}/api/trpc/mariadb.deploy`, {
|
|
55
|
+
json: {
|
|
56
|
+
mariadbId,
|
|
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 mariadb"));
|
|
66
|
+
}
|
|
67
|
+
this.log(chalk.green("Mariadb deploy 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 DatabaseMariadbStop extends Command {
|
|
8
|
+
static description = "Stop an mariadb from a project.";
|
|
9
|
+
static examples = ["$ <%= config.bin %> mariadb 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 mariadb 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.mariadb.length === 0) {
|
|
28
|
+
this.error(chalk.yellow("No mariadb found in this project."));
|
|
29
|
+
}
|
|
30
|
+
const appAnswers = await inquirer.prompt([
|
|
31
|
+
{
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
choices: projectSelected.mariadb.map((app) => ({
|
|
34
|
+
name: app.name,
|
|
35
|
+
value: app.mariadbId,
|
|
36
|
+
})),
|
|
37
|
+
message: "Select the mariadb to stop:",
|
|
38
|
+
name: "selectedApp",
|
|
39
|
+
type: "list",
|
|
40
|
+
},
|
|
41
|
+
]);
|
|
42
|
+
const mariadbId = appAnswers.selectedApp;
|
|
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."));
|
|
53
|
+
}
|
|
54
|
+
const response = await axios.post(`${auth.url}/api/trpc/mariadb.stop`, {
|
|
55
|
+
json: {
|
|
56
|
+
mariadbId,
|
|
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 mariadb"));
|
|
66
|
+
}
|
|
67
|
+
this.log(chalk.green("Mariadb stop successful."));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Command } from "@oclif/core";
|
|
2
|
+
export default class DatabaseMongoCreate 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 { readAuthConfig } from "../../../utils/utils.js";
|
|
6
|
+
import { getProjects } from "../../../utils/shared.js";
|
|
7
|
+
import { slugify } from "../../../utils/slug.js";
|
|
8
|
+
export default class DatabaseMongoCreate extends Command {
|
|
9
|
+
static description = "Create a new MongoDB database within a project.";
|
|
10
|
+
static examples = ["$ <%= config.bin %> mongo 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(DatabaseMongoCreate);
|
|
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 MongoDB 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: "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",
|
|
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/mongo.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 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}`));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Command } from "@oclif/core";
|
|
2
|
+
export default class DatabaseMongoDelete 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,95 @@
|
|
|
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 DatabaseMongoDelete extends Command {
|
|
8
|
+
static description = "Delete a MongoDB database from a project.";
|
|
9
|
+
static examples = [
|
|
10
|
+
"$ <%= config.bin %> mongo delete",
|
|
11
|
+
"$ <%= config.bin %> mongo 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(DatabaseMongoDelete);
|
|
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 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;
|
|
49
|
+
}
|
|
50
|
+
const appAnswers = await inquirer.prompt([
|
|
51
|
+
{
|
|
52
|
+
choices: project.mongo.map((db) => ({
|
|
53
|
+
name: db.name,
|
|
54
|
+
value: db.mongoId,
|
|
55
|
+
})),
|
|
56
|
+
message: "Select the MongoDB database to delete:",
|
|
57
|
+
name: "selectedApp",
|
|
58
|
+
type: "list",
|
|
59
|
+
},
|
|
60
|
+
]);
|
|
61
|
+
const mongoId = appAnswers.selectedApp;
|
|
62
|
+
const confirmAnswers = await inquirer.prompt([
|
|
63
|
+
{
|
|
64
|
+
default: false,
|
|
65
|
+
message: "Are you sure you want to delete this MongoDB 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/mongo.remove`, {
|
|
75
|
+
json: {
|
|
76
|
+
mongoId,
|
|
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 MongoDB database"));
|
|
86
|
+
}
|
|
87
|
+
this.log(chalk.green("MongoDB database deleted successfully."));
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
this.error(
|
|
91
|
+
// @ts-ignore
|
|
92
|
+
chalk.red(`Failed to delete MongoDB database: ${error.message}`));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -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 DatabaseMongoDeploy extends Command {
|
|
8
|
+
static description = "Deploy an mongo 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 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 deploy:",
|
|
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 deploy this mongo?",
|
|
47
|
+
name: "confirmDelete",
|
|
48
|
+
type: "confirm",
|
|
49
|
+
},
|
|
50
|
+
]);
|
|
51
|
+
if (!confirmAnswers.confirmDelete) {
|
|
52
|
+
this.error(chalk.yellow("mongo deployment cancelled."));
|
|
53
|
+
}
|
|
54
|
+
const response = await axios.post(`${auth.url}/api/trpc/mongo.deploy`, {
|
|
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 deploying mongo"));
|
|
66
|
+
}
|
|
67
|
+
this.log(chalk.green("Mongo deploy successful."));
|
|
68
|
+
}
|
|
69
|
+
}
|