@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.
Files changed (77) hide show
  1. package/README.md +112 -0
  2. package/bin/dev.cmd +3 -0
  3. package/bin/dev.js +6 -0
  4. package/bin/run.cmd +3 -0
  5. package/bin/run.js +5 -0
  6. package/dist/commands/app/create.d.ts +13 -0
  7. package/dist/commands/app/create.js +77 -0
  8. package/dist/commands/app/delete.d.ts +9 -0
  9. package/dist/commands/app/delete.js +84 -0
  10. package/dist/commands/app/deploy.d.ts +6 -0
  11. package/dist/commands/app/deploy.js +69 -0
  12. package/dist/commands/app/stop.d.ts +6 -0
  13. package/dist/commands/app/stop.js +69 -0
  14. package/dist/commands/authenticate.d.ts +10 -0
  15. package/dist/commands/authenticate.js +79 -0
  16. package/dist/commands/database/mariadb/create.d.ts +9 -0
  17. package/dist/commands/database/mariadb/create.js +105 -0
  18. package/dist/commands/database/mariadb/delete.d.ts +9 -0
  19. package/dist/commands/database/mariadb/delete.js +95 -0
  20. package/dist/commands/database/mariadb/deploy.d.ts +6 -0
  21. package/dist/commands/database/mariadb/deploy.js +69 -0
  22. package/dist/commands/database/mariadb/stop.d.ts +6 -0
  23. package/dist/commands/database/mariadb/stop.js +69 -0
  24. package/dist/commands/database/mongo/create.d.ts +9 -0
  25. package/dist/commands/database/mongo/create.js +107 -0
  26. package/dist/commands/database/mongo/delete.d.ts +9 -0
  27. package/dist/commands/database/mongo/delete.js +95 -0
  28. package/dist/commands/database/mongo/deploy.d.ts +6 -0
  29. package/dist/commands/database/mongo/deploy.js +69 -0
  30. package/dist/commands/database/mongo/stop.d.ts +6 -0
  31. package/dist/commands/database/mongo/stop.js +69 -0
  32. package/dist/commands/database/mysql/create.d.ts +9 -0
  33. package/dist/commands/database/mysql/create.js +112 -0
  34. package/dist/commands/database/mysql/delete.d.ts +9 -0
  35. package/dist/commands/database/mysql/delete.js +97 -0
  36. package/dist/commands/database/mysql/deploy.d.ts +6 -0
  37. package/dist/commands/database/mysql/deploy.js +69 -0
  38. package/dist/commands/database/mysql/stop.d.ts +6 -0
  39. package/dist/commands/database/mysql/stop.js +69 -0
  40. package/dist/commands/database/postgres/create.d.ts +9 -0
  41. package/dist/commands/database/postgres/create.js +107 -0
  42. package/dist/commands/database/postgres/delete.d.ts +9 -0
  43. package/dist/commands/database/postgres/delete.js +94 -0
  44. package/dist/commands/database/postgres/deploy.d.ts +6 -0
  45. package/dist/commands/database/postgres/deploy.js +69 -0
  46. package/dist/commands/database/postgres/stop.d.ts +6 -0
  47. package/dist/commands/database/postgres/stop.js +69 -0
  48. package/dist/commands/database/redis/create.d.ts +9 -0
  49. package/dist/commands/database/redis/create.js +95 -0
  50. package/dist/commands/database/redis/delete.d.ts +9 -0
  51. package/dist/commands/database/redis/delete.js +96 -0
  52. package/dist/commands/database/redis/deploy.d.ts +6 -0
  53. package/dist/commands/database/redis/deploy.js +69 -0
  54. package/dist/commands/database/redis/stop.d.ts +6 -0
  55. package/dist/commands/database/redis/stop.js +69 -0
  56. package/dist/commands/project/create.d.ts +10 -0
  57. package/dist/commands/project/create.js +74 -0
  58. package/dist/commands/project/info.d.ts +10 -0
  59. package/dist/commands/project/info.js +122 -0
  60. package/dist/commands/project/list.d.ts +6 -0
  61. package/dist/commands/project/list.js +43 -0
  62. package/dist/commands/verify.d.ts +6 -0
  63. package/dist/commands/verify.js +45 -0
  64. package/dist/index.d.ts +1 -0
  65. package/dist/index.js +1 -0
  66. package/dist/utils/http.d.ts +4 -0
  67. package/dist/utils/http.js +4 -0
  68. package/dist/utils/shared.d.ts +10 -0
  69. package/dist/utils/shared.js +55 -0
  70. package/dist/utils/slug.d.ts +1 -0
  71. package/dist/utils/slug.js +12 -0
  72. package/dist/utils/slugify.d.ts +3 -0
  73. package/dist/utils/slugify.js +2 -0
  74. package/dist/utils/utils.d.ts +6 -0
  75. package/dist/utils/utils.js +19 -0
  76. package/oclif.manifest.json +895 -0
  77. package/package.json +87 -0
@@ -0,0 +1,6 @@
1
+ import { Command } from "@oclif/core";
2
+ export default class DatabasePostgresDeploy extends Command {
3
+ static description: string;
4
+ static examples: string[];
5
+ run(): Promise<void>;
6
+ }
@@ -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 DatabasePostgresDeploy extends Command {
8
+ static description = "Deploy an postgres 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 postgres 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.postgres.length === 0) {
28
+ this.error(chalk.yellow("No postgres found in this project."));
29
+ }
30
+ const appAnswers = await inquirer.prompt([
31
+ {
32
+ // @ts-ignore
33
+ choices: projectSelected.postgres.map((app) => ({
34
+ name: app.name,
35
+ value: app.postgresId,
36
+ })),
37
+ message: "Select the postgres to deploy:",
38
+ name: "selectedApp",
39
+ type: "list",
40
+ },
41
+ ]);
42
+ const postgresId = appAnswers.selectedApp;
43
+ const confirmAnswers = await inquirer.prompt([
44
+ {
45
+ default: false,
46
+ message: "Are you sure you want to deploy this postgres?",
47
+ name: "confirmDelete",
48
+ type: "confirm",
49
+ },
50
+ ]);
51
+ if (!confirmAnswers.confirmDelete) {
52
+ this.error(chalk.yellow("postgres deployment cancelled."));
53
+ }
54
+ const response = await axios.post(`${auth.url}/api/trpc/postgres.deploy`, {
55
+ json: {
56
+ postgresId,
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 postgres"));
66
+ }
67
+ this.log(chalk.green("Postgres deployed successful."));
68
+ }
69
+ }
@@ -0,0 +1,6 @@
1
+ import { Command } from "@oclif/core";
2
+ export default class DatabasePostgresStop extends Command {
3
+ static description: string;
4
+ static examples: string[];
5
+ run(): Promise<void>;
6
+ }
@@ -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 DatabasePostgresStop extends Command {
8
+ static description = "Stop an postgres from a project.";
9
+ static examples = ["$ <%= config.bin %> postgres 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 postgres 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.postgres.length === 0) {
28
+ this.error(chalk.yellow("No postgres found in this project."));
29
+ }
30
+ const appAnswers = await inquirer.prompt([
31
+ {
32
+ // @ts-ignore
33
+ choices: projectSelected.postgres.map((app) => ({
34
+ name: app.name,
35
+ value: app.postgresId,
36
+ })),
37
+ message: "Select the postgres to stop:",
38
+ name: "selectedApp",
39
+ type: "list",
40
+ },
41
+ ]);
42
+ const postgresId = appAnswers.selectedApp;
43
+ const confirmAnswers = await inquirer.prompt([
44
+ {
45
+ default: false,
46
+ message: "Are you sure you want to stop this postgres?",
47
+ name: "confirmDelete",
48
+ type: "confirm",
49
+ },
50
+ ]);
51
+ if (!confirmAnswers.confirmDelete) {
52
+ this.error(chalk.yellow("postgres stop cancelled."));
53
+ }
54
+ const response = await axios.post(`${auth.url}/api/trpc/postgres.stop`, {
55
+ json: {
56
+ postgresId,
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 postgres"));
66
+ }
67
+ this.log(chalk.green("Postgres stop successful."));
68
+ }
69
+ }
@@ -0,0 +1,9 @@
1
+ import { Command } from "@oclif/core";
2
+ export default class DatabaseRedisCreate 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 { slugify } from "../../../utils/slug.js";
6
+ import { readAuthConfig } from "../../../utils/utils.js";
7
+ import { getProjects } from "../../../utils/shared.js";
8
+ export default class DatabaseRedisCreate extends Command {
9
+ static description = "Create a new Redis database within a project.";
10
+ static examples = ["$ <%= config.bin %> redis 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(DatabaseRedisCreate);
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 Redis 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: "Enter the database description (optional):",
46
+ name: "description",
47
+ type: "input",
48
+ },
49
+ {
50
+ message: "Database password (optional):",
51
+ name: "databasePassword",
52
+ type: "password",
53
+ },
54
+ {
55
+ default: "redis:7",
56
+ message: "Docker Image (default: redis:7):",
57
+ name: "dockerImage",
58
+ type: "input",
59
+ },
60
+ ]);
61
+ const appName = await inquirer.prompt([
62
+ {
63
+ default: `${slugify(project.name)}-${dbDetails.name}`,
64
+ message: "Enter the App name:",
65
+ name: "appName",
66
+ type: "input",
67
+ validate: (input) => (input ? true : "App name is required"),
68
+ },
69
+ ]);
70
+ try {
71
+ const response = await axios.post(`${auth.url}/api/trpc/redis.create`, {
72
+ json: {
73
+ ...dbDetails,
74
+ appName: appName.appName,
75
+ projectId: project.projectId,
76
+ },
77
+ }, {
78
+ headers: {
79
+ Authorization: `Bearer ${auth.token}`,
80
+ "Content-Type": "application/json",
81
+ },
82
+ });
83
+ if (!response.data.result.data.json) {
84
+ this.error(chalk.red("Error creating Redis database"));
85
+ }
86
+ this.log(chalk.green(`Redis database '${dbDetails.name}' created successfully.`));
87
+ }
88
+ catch (error) {
89
+ this.error(
90
+ // @ts-ignore
91
+ chalk.red(`Failed to create Redis database: ${error.message}`));
92
+ }
93
+ }
94
+ }
95
+ }
@@ -0,0 +1,9 @@
1
+ import { Command } from "@oclif/core";
2
+ export default class DatabaseRedisDelete 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,96 @@
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 DatabaseRedisDelete extends Command {
8
+ static description = "Delete an redis database from a project.";
9
+ static examples = [
10
+ "$ <%= config.bin %> redis delete",
11
+ "$ <%= config.bin %> redis 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(DatabaseRedisDelete);
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 redis 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.redis || project.redis.length === 0) {
47
+ this.log(chalk.yellow("No redis 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.redis.map((db) => ({
54
+ name: db.name,
55
+ value: db.redisId,
56
+ })),
57
+ message: "Select the redis database to delete:",
58
+ name: "selectedApp",
59
+ type: "list",
60
+ },
61
+ ]);
62
+ const redisId = appAnswers.selectedApp;
63
+ const confirmAnswers = await inquirer.prompt([
64
+ {
65
+ default: false,
66
+ message: "Are you sure you want to delete this redis database?",
67
+ name: "confirmDelete",
68
+ type: "confirm",
69
+ },
70
+ ]);
71
+ if (!confirmAnswers.confirmDelete) {
72
+ this.log(chalk.yellow("Database deletion cancelled."));
73
+ return;
74
+ }
75
+ const deleteResponse = await axios.post(`${auth.url}/api/trpc/redis.remove`, {
76
+ json: {
77
+ redisId,
78
+ },
79
+ }, {
80
+ headers: {
81
+ Authorization: `Bearer ${auth.token}`,
82
+ "Content-Type": "application/json",
83
+ },
84
+ });
85
+ if (!deleteResponse.data.result.data.json) {
86
+ this.error(chalk.red("Error deleting redis database"));
87
+ }
88
+ this.log(chalk.green("Redis database deleted successfully."));
89
+ }
90
+ catch (error) {
91
+ this.error(
92
+ // @ts-expect-error - TS2339: Property 'data' does not exist on type 'AxiosError<any>'.
93
+ chalk.red(`Failed to delete redis database: ${error.message}`));
94
+ }
95
+ }
96
+ }
@@ -0,0 +1,6 @@
1
+ import { Command } from "@oclif/core";
2
+ export default class DatabaseRedisDeploy extends Command {
3
+ static description: string;
4
+ static examples: string[];
5
+ run(): Promise<void>;
6
+ }
@@ -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 DatabaseRedisDeploy extends Command {
8
+ static description = "Deploy an redis 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 redis 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.redis.length === 0) {
28
+ this.error(chalk.yellow("No redis found in this project."));
29
+ }
30
+ const appAnswers = await inquirer.prompt([
31
+ {
32
+ // @ts-ignore
33
+ choices: projectSelected.redis.map((app) => ({
34
+ name: app.name,
35
+ value: app.redisId,
36
+ })),
37
+ message: "Select the redis to deploy:",
38
+ name: "selectedApp",
39
+ type: "list",
40
+ },
41
+ ]);
42
+ const redisId = appAnswers.selectedApp;
43
+ const confirmAnswers = await inquirer.prompt([
44
+ {
45
+ default: false,
46
+ message: "Are you sure you want to deploy this redis?",
47
+ name: "confirmDelete",
48
+ type: "confirm",
49
+ },
50
+ ]);
51
+ if (!confirmAnswers.confirmDelete) {
52
+ this.error(chalk.yellow("redis deployment cancelled."));
53
+ }
54
+ const response = await axios.post(`${auth.url}/api/trpc/redis.deploy`, {
55
+ json: {
56
+ redisId,
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 redis"));
66
+ }
67
+ this.log(chalk.green("Redis deployed successful."));
68
+ }
69
+ }
@@ -0,0 +1,6 @@
1
+ import { Command } from "@oclif/core";
2
+ export default class DatabaseRedisStop extends Command {
3
+ static description: string;
4
+ static examples: string[];
5
+ run(): Promise<void>;
6
+ }
@@ -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 DatabaseRedisStop extends Command {
8
+ static description = "Stop an redis from a project.";
9
+ static examples = ["$ <%= config.bin %> redis 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 redis 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.redis.length === 0) {
28
+ this.error(chalk.yellow("No redis found in this project."));
29
+ }
30
+ const appAnswers = await inquirer.prompt([
31
+ {
32
+ // @ts-ignore
33
+ choices: projectSelected.redis.map((app) => ({
34
+ name: app.name,
35
+ value: app.redisId,
36
+ })),
37
+ message: "Select the redis to stop:",
38
+ name: "selectedApp",
39
+ type: "list",
40
+ },
41
+ ]);
42
+ const redisId = appAnswers.selectedApp;
43
+ const confirmAnswers = await inquirer.prompt([
44
+ {
45
+ default: false,
46
+ message: "Are you sure you want to stop this redis?",
47
+ name: "confirmDelete",
48
+ type: "confirm",
49
+ },
50
+ ]);
51
+ if (!confirmAnswers.confirmDelete) {
52
+ this.error(chalk.yellow("redis stop cancelled."));
53
+ }
54
+ const response = await axios.post(`${auth.url}/api/trpc/redis.stop`, {
55
+ json: {
56
+ redisId,
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 redis"));
66
+ }
67
+ this.log(chalk.green("Redis stop successful."));
68
+ }
69
+ }
@@ -0,0 +1,10 @@
1
+ import { Command } from "@oclif/core";
2
+ export default class ProjectCreate extends Command {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
6
+ description: 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
+ };
9
+ run(): Promise<void>;
10
+ }
@@ -0,0 +1,74 @@
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
+ export default class ProjectCreate extends Command {
7
+ static description = "Create a new project with an optional description.";
8
+ static examples = [
9
+ "$ <%= config.bin %> <%= command.id %> -n MyProject -d 'This is my project description'",
10
+ "$ <%= config.bin %> <%= command.id %> -n MyProject",
11
+ "$ <%= config.bin %> <%= command.id %>",
12
+ ];
13
+ static flags = {
14
+ description: Flags.string({
15
+ char: "d",
16
+ description: "Description of the project",
17
+ required: false,
18
+ }),
19
+ name: Flags.string({
20
+ char: "n",
21
+ description: "Name of the project",
22
+ required: false,
23
+ }),
24
+ };
25
+ async run() {
26
+ const auth = await readAuthConfig(this);
27
+ console.log(chalk.blue.bold("\n Create a New Project \n"));
28
+ const { flags } = await this.parse(ProjectCreate);
29
+ let answers = {};
30
+ const questions = [];
31
+ if (!flags.name) {
32
+ questions.push({
33
+ message: chalk.green("Enter the project name:"),
34
+ name: "name",
35
+ type: "input",
36
+ validate: (input) => (input ? true : "Project name is required"),
37
+ });
38
+ }
39
+ if (!flags.description) {
40
+ questions.push({
41
+ default: "",
42
+ message: chalk.green("Enter the project description (optional):"),
43
+ name: "description",
44
+ type: "input",
45
+ });
46
+ }
47
+ if (questions.length > 0) {
48
+ answers = await inquirer.prompt(questions);
49
+ }
50
+ const name = flags.name || answers.name;
51
+ const description = flags.description || answers.description;
52
+ try {
53
+ const response = await axios.post(`${auth.url}/api/trpc/project.create`, {
54
+ json: {
55
+ description,
56
+ name,
57
+ },
58
+ }, {
59
+ headers: {
60
+ Authorization: `Bearer ${auth.token}`,
61
+ "Content-Type": "application/json",
62
+ },
63
+ });
64
+ if (!response.data.result.data.json) {
65
+ this.error(chalk.red("Error`"));
66
+ }
67
+ this.log(chalk.green(`Project '${name}' created successfully.`));
68
+ }
69
+ catch (error) {
70
+ // @ts-expect-error hola
71
+ this.error(chalk.red(`Failed to create project: ${error.message}`));
72
+ }
73
+ }
74
+ }
@@ -0,0 +1,10 @@
1
+ import { Command } from "@oclif/core";
2
+ export default class ProjectInfo 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
+ private showProjectInfo;
10
+ }